Open xml file with different extension using loadXMLDoc
I've got a file with an extension of .abc which is an XML file and I am processing the XML using XSL.
I open an HTML page which loads the XML usi开发者_如何学JAVAng loadXMLDoc like this:
xml=loadXMLDoc("Example.xml");
xsl=loadXMLDoc("Example.xsl");
The problem is I need to open "Example.abc" not "Example.xml". If I try:
xml=loadXMLDoc("Example.abc");
the page loads but with no data.
Is there a way I can load the .abc file?
It is not clear exactly what you are referring to here.
Do you mean the loadXMLDoc function that is introducted here at w3Schools.com?
function loadXMLDoc(dname)
{
if (window.XMLHttpRequest)
{
xhttp=new XMLHttpRequest();
}
else
{
xhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xhttp.open("GET",dname,false);
xhttp.send("");
return xhttp.responseXML;
}
I just tried playing around with this and it works perfectly well with any file extension for the .xml - one thing I did notice is that the browser was caching the html so that I had to close and reopen the page (when it was just on my desktop) to refresh the file name I had.
Could this be your issue?
Did have the same problem. XMLHttpRequest.get
requires a xml mime type.
To solve this, insert
if (xhttp.overrideMimeType) xhttp.overrideMimeType("text/xml");
before the xhttp.open("GET", dname, false);
line in the xsl file
精彩评论