Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

XML parsing in Firefox

I've been trying to figure this out for some time now to no avail. Basically, I'm trying to read the contents of a simple xml doc and insert a matching value into a span i have in my html xslt document. everything works 100% in IE, but firefox won't load any of the elements properly -- whenever i try to access anything after the doc is loaded i am given an "elementSuchandsuch as no properties" error.

any help on this would be most appreciated. relevant code is below...

XSLT: calling javascript function from within a span element

<a href="#" class="definable">Definable<span><script>document.write(getDefinition("Chat"));</script></span></a> This is filler text.

JAVASCRIPT: (starts in getDefinition, goes to load, which verifies for IE only, then back to getDFefinition for text formatting, etc)

var objXML;

function getDefinition(term){

importXML("terms.xml");

for (var x=0; objXML.childNodes[x].text!=""; x++)
{
if (objXML.childNodes[x].getAttribute("id")==term){
return "<B>Definition: " + objXML.childNodes[x].getAttribute("id") + "</B><br/>" + objXML.childNodes[x].text;
}
}

return "No definition is available for this term."

}

function importXML(doc)
{
if (document.implementation && document.implementation.createDocument)
{
xmlDoc = document.implementation.createDocument("","",null);
xmlDoc.load(doc);
xmlDoc.onload = alert(xmlDoc.getElementsByTagName("term")[0].firstChild);
}
else if (window.ActiveXObject)
{
objXML = new ActiveXObject("Microsoft.XMLDOM");
objXML.async="false";
objXML.onreadystatechange=verify;
objXML.load(doc);
objXML=objXML.documentElement;
}
else
{
alert('Your browser can\'t handle this script');
return;
}
}

function verify()
{
// 0 Object is not initialized
// 1 Loading object is loading data
// 2 Loaded object has loaded data
// 3 Data from object can be worked with
// 4 Object completely initialized



if (objXML.readyState != 4 )
{
return false;
}
}
[2330 byte] By [staceass] at [2007-11-11 10:31:44]