M
mr_burns
Hi there,
I am using the following function to import a xml file whether the
users browser be IE or Mozilla:
function importXML(file) {
var xmlDoc;
var moz = (typeof document.implementation != 'undefined') && (typeof
document.implementation.createDocument != 'undefined');
var ie = (typeof window.ActiveXObject != 'undefined');
if (moz) {
xmlDoc = document.implementation.createDocument("", "", null)
//do I need something else here???
} else if (ie) {
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async = false;
while(xmlDoc.readyState != 4) {};
}
xmlDoc.load(file);
return xmlDoc
}
An example call of this function looks like this:
importXML('xml/books.xml')
The code for IE works well as I have used code to access the XML file
im using but the code for Mozilla doesnt work. I got the funxtion from
a tutorial site, http://www.sitepoint.com/article/xml-javascript-mozilla.
Am I missing something after the line 'xmlDoc =
document.implementation.cre...?? On the tutorial it had a line
xmlDoc.onload = readXML but that appears to be some kind of function,
readXML, and isnt shown on the tutorial. How do I get the variable
xmlDoc to the same stage as the code used for IE so that I can then
perform something like after the function is run??:
nodes = xmlDoc.getElementsByTagName("title")
or
nodes = xmlDoc.documentElement.childNodes
If I try the above in Mozilla and do something like nodes.length I get
0 (wrong) whereas if I do it in IE, I get 10 (correct). Is the 'nodes
= ...' code only able to run in IE or is the variable, xmlDoc, not
properly prepared in Mozilla to do the above?? The results I get in
Mozilla lead me to assume either but I may be wrong. Any help would be
great.
Cheers
Burnsy
I am using the following function to import a xml file whether the
users browser be IE or Mozilla:
function importXML(file) {
var xmlDoc;
var moz = (typeof document.implementation != 'undefined') && (typeof
document.implementation.createDocument != 'undefined');
var ie = (typeof window.ActiveXObject != 'undefined');
if (moz) {
xmlDoc = document.implementation.createDocument("", "", null)
//do I need something else here???
} else if (ie) {
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async = false;
while(xmlDoc.readyState != 4) {};
}
xmlDoc.load(file);
return xmlDoc
}
An example call of this function looks like this:
importXML('xml/books.xml')
The code for IE works well as I have used code to access the XML file
im using but the code for Mozilla doesnt work. I got the funxtion from
a tutorial site, http://www.sitepoint.com/article/xml-javascript-mozilla.
Am I missing something after the line 'xmlDoc =
document.implementation.cre...?? On the tutorial it had a line
xmlDoc.onload = readXML but that appears to be some kind of function,
readXML, and isnt shown on the tutorial. How do I get the variable
xmlDoc to the same stage as the code used for IE so that I can then
perform something like after the function is run??:
nodes = xmlDoc.getElementsByTagName("title")
or
nodes = xmlDoc.documentElement.childNodes
If I try the above in Mozilla and do something like nodes.length I get
0 (wrong) whereas if I do it in IE, I get 10 (correct). Is the 'nodes
= ...' code only able to run in IE or is the variable, xmlDoc, not
properly prepared in Mozilla to do the above?? The results I get in
Mozilla lead me to assume either but I may be wrong. Any help would be
great.
Cheers
Burnsy