K
KB
Hi folks,
I'm trying to adopt microsoft-specific code to mozilla. I have an xml
file which I can't figure out how to parse using the XMLDocument
object:
<?xml version="1.0" encoding="utf-16" ?>
<locations>
<loc id="401" name="one" />
<loc id="402" name="two" />
<loc id="403" name="three" />
</locations>
here's the code:
var xmlfile = <above...>
xmldoc = document.implementation.createDocument( "", "", null );
xmldoc.addEventListener("load", onload, false);
xmldoc.load( xmlfile );
.....
.....
function onload( evt )
{
// the following code works in IE, but in NS childNodes is
empty
var locs = xmldoc.childNodes[0];
for ( var i=0; i<locs.childNodes.length; i++ )
{
elem = locs.childNodes;
if ( elem.nodeName == "loc" )
{
var id = elem.attributes[0].value;
var name = elem.attributes[1].value;
alert( 'location : ' + id + ',' + name );
}
}
}
Any help is greatly appreciated
Kevin
I'm trying to adopt microsoft-specific code to mozilla. I have an xml
file which I can't figure out how to parse using the XMLDocument
object:
<?xml version="1.0" encoding="utf-16" ?>
<locations>
<loc id="401" name="one" />
<loc id="402" name="two" />
<loc id="403" name="three" />
</locations>
here's the code:
var xmlfile = <above...>
xmldoc = document.implementation.createDocument( "", "", null );
xmldoc.addEventListener("load", onload, false);
xmldoc.load( xmlfile );
.....
.....
function onload( evt )
{
// the following code works in IE, but in NS childNodes is
empty
var locs = xmldoc.childNodes[0];
for ( var i=0; i<locs.childNodes.length; i++ )
{
elem = locs.childNodes;
if ( elem.nodeName == "loc" )
{
var id = elem.attributes[0].value;
var name = elem.attributes[1].value;
alert( 'location : ' + id + ',' + name );
}
}
}
Any help is greatly appreciated
Kevin