The xml and javascript are below.
IE finds everything fine, Firefox gives the following error -
xmlDoc.getEleme ntsByTagName("l ab_name")[0] has no properties
on this line -
alert(xmlDoc.ge tElementsByTagN ame('lab_name')[0].childNodes[0].nodeValue);
I am using Firebug to help me debug. When I look at the DOM right after the page loads the childNodes part of my xmlDoc tree is empty, this explains why I get the error.
But why is it empty????!!!!!
It should have the xml structure in it.
To top it off, if I close the childNodes part of the tree (hide it) and then show it again by clicking the arrow to the left of it, Firebug finds everything!!!!! !!!!!!!!!!
All help is greatly appreciated!
XML File Example :
Javascript To Read It :
IE finds everything fine, Firefox gives the following error -
xmlDoc.getEleme ntsByTagName("l ab_name")[0] has no properties
on this line -
alert(xmlDoc.ge tElementsByTagN ame('lab_name')[0].childNodes[0].nodeValue);
I am using Firebug to help me debug. When I look at the DOM right after the page loads the childNodes part of my xmlDoc tree is empty, this explains why I get the error.
But why is it empty????!!!!!
It should have the xml structure in it.
To top it off, if I close the childNodes part of the tree (hide it) and then show it again by clicking the arrow to the left of it, Firebug finds everything!!!!! !!!!!!!!!!
All help is greatly appreciated!
XML File Example :
Code:
<?xml version="1.0" encoding="iso-8859-1"?> <lab> <lab_name>My Lab</lab_name> <about> <description><![CDATA[A paragraph describing my lab!]]></description> <image>images/path/myimage.jpg</image> </about> </lab>
Code:
<script language="javascript">
if (window.ActiveXObject)
{
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async=false;
xmlDoc.load("xml/test_xml.xml");
alert(xmlDoc.getElementsByTagName('lab_name')[0].childNodes[0].nodeValue);
alert(xmlDoc.getElementsByTagName('description')[0].childNodes[0].nodeValue);
alert(xmlDoc.getElementsByTagName('image')[0].childNodes[0].nodeValue);
}
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation && document.implementation.createDocument)
{
xmlDoc = document.implementation.createDocument("", "", null);
xmlDoc.load("xml/test_xml.xml");
alert(xmlDoc.getElementsByTagName('lab_name')[0].childNodes[0].nodeValue);
alert(xmlDoc.getElementsByTagName('description')[0].childNodes[0].nodeValue);
alert(xmlDoc.getElementsByTagName('image')[0].childNodes[0].nodeValue);
}
// no good browser found
else
{
if (!xmlDoc.load("xml/test_xml.xml"))
{
alert ("Failed to load XML data source!");
}
}
Comment