Is there a way to change the content type of an XML document in an XML document?

Is there a way to change the content type of an XML document in an XML document?

I am working with a really old system that transmits HTML (and we are trying to return XML). I am retrieving it from XMLHttpRequest and I noticed using netcat that it is not passing content headers.

When I receive XMLHttpRequest.responseXML, responseText exists, but responseXML is null.

I've already checked the returned XML to see if it's well-formed and what it looks like (it's a very short document).

0


source to share


3 answers


Not. Content-Type

when you link to it (in the comments to your question) is part of the HTTP headers.

And HTTP is just a transport for (say) XML documents. They are useful, they don't know anything about HTTP headers, so they cannot change them.



What you probably mean is: "Is there an equivalent <meta http-equiv="...

in XML. No, no. Even HTML cannot change the HTTP headers, it can only cause the user agent to behave differently. This is useful if the HTML file was saved to disk, and when loaded, the user agents have no headers.

In XML, all the information you need is in the processing instructions ( <?xml version="1.0" encoding="UTF-8"?>

) at the top of the file. Header information is not required to load / display properly.

+1


source


Not.



By the time the UA can get to any such tag, it should have already decided which document it parses.

0


source


I figured out this is a question using the string xhr.responseText and generating an XML document from it:

function createDOMFromString(sXml){

    var browser = navigator.appName;
    var oXmlDom = null;

    // IE Implementation...
    if(browser == "Microsoft Internet Explorer") {
         oXmlDom=new ActiveXObject("Microsoft.XMLDOM");
         oXmlDom.async="false";
         oXmlDom.loadXML(sXml);
    }
    // FF Implementation...
    else {
        var oParser = new DOMParser();
        oXmlDom = oParser.parseFromString(sXml, "text/xml");
    }
    // TODO: If we need it Safari implementation.

    return oXmlDom;
}

      

Hooray!

0


source







All Articles