|
I've seen numerous iterations of this problem, but none of the proposed solutions work for me. When I use getElementsByTag() on an XML document, IE returns 2 hits but FF returns 0. I'll post both the loading function and relevant functions:
[PHP]function loadXML(){
// code for IE
if (window.ActiveXObject){
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async=false;
xmlDoc.load("twl.xml");
oddBrowser=false;
setupTeam();
}
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation &&
document.implementation.createDocument){
oddBrowser = true;
xmlDoc=document.implementation.createDocument(""," ",null);
xmlDoc.load("twl.xml");
xmlDoc.onload = setupTeam();
}
else
{
alert('Your browser cannot handle this script');
}
}[/PHP]
[PHP]function setupTeam(){ //Fails in FF
debugit('Entered Team Setup')
var name;
var url;
name = getChild(xmlDoc,"name");
debugit('Name: ' + name);
url = getChild(xmlDoc,"url");
debugit('URL: ' + url);
strOut += "<tr><td>" + "<a href=\"" + url + "\">" + name + "\
</a></td></tr>";
setupLadders();
}[/PHP]
[PHP]function getChild(cNode,target){
var retNode;
debugit('cNode: ' + cNode.nodeName + ' Target: ' + target);
var numTgts = cNode.getElementsByTagName(target).length;
debugit('Number of \"' + target + '\"s in ' + cNode.nodeName + ': ' + numTgts);
var i = 0;
do{
debugit('Entered do loop');
retNode = cNode.getElementsByTagName(target)[0].childNodes[i];
debugit('Current retNode value: ' + retNode.nodeValue);
i++;
}while(retNode.nodeType!=3)
debugit('retNode: ' + retNode.nodeName);
return retNode.nodeValue;
}[/PHP]
I get to the getElementsByTagName(target)[0] and FF's error console says that it has no properties (I'm assuming because it doesn't exist). I'm not sure what is wrong. The only other thing is that this is all being done locally, with the HTML file and XML file loaded into a directory on my HDD. I run the script by viewing the HTML page locally.
|