Adonis wrote:
Adonis wrote:
I have an XML file hosted by my ISP free web space. It naively treats
the file as text/plain.
Then contact your ISP to change the server settings so that XML is
served as application/xml. Or ask them which file suffix they have
associated with the MIME type application/xml or text/xml, perhaps they
have choosen something else that .xml.
I would like to convert this data into a DOM
object.
Mozilla has a method overrideMimeType that allows you to get the
plain/text parsed by the XML parser, you can do
var httpRequest = new XMLHttpRequest();
httpRequest.open('GET', 'test2005071301.txt', true);
if (typeof httpRequest.overrideMimeType != 'undefined') {
httpRequest.overrideMimeType('application/xml');
}
httpRequest.onreadystatechange = function () {
if (httpRequest.readyState == 4) {
alert(httpRequest.responseXML.getElementsByTagName ('*').length);
}
};
httpRequest.send(null);
I don't know of any other browser implementing that method but Opera 8
seems to parse the response as XML even if it is not delivered with an
XML MIME type.
Not sure what Safari does.
IE with MSXML will not parse text/plain as XML so you have good reasons
to ask your ISP to change the settings.
As a workaround you can try to parse responseText with MSXML yourself
but you should be aware that the approach has shortcomings when it comes
to using encodings other that UTF-8. You would simply pass the
responseText to the loadXML method see
<http://www.faqts.com/knowledge_base/view.phtml/aid/15302/fid/616>
--
Martin Honnen
http://JavaScript.FAQTs.com/