Skip to main content
gamedev.net
🔒 Locked

[web] XML, mozilla

Started by EvilCrap 1 reply 800+ views
Original Post
EvilCrap
EvilCrap
I've been researching XML on the web, and everyone does seem to have examples of how to get mozilla to work -but i cant get it to work! On IE my code works. for instance, i do a getElementByTagName.length, and get 1, while on mozilla, i get 0. moz doesnt have any problem drawing the xml file, so it seems valid. I really need to get xml to work for mozilla! This is my mozilla code:

//xmldoc is a global in the html/javascript header
xmldoc = document.implementation.createDocument("", "", null);
xmldoc.onload = readXML; // i tried null here too, readXML is an empty function
xmldoc.load( xmlfile );
//... in body/javascript
var numFiles = xmldoc.getElementsByTagName( "files" ).length;
//this sets numFiles= 0, when it should be 1

this is the xml file:

<?xml version="1.0" ?>
<files>
    <file id="001">file1</file>
    <file id="002">file2</file>
    <file id="003">file3</file>
</files>

anyone know what is up, and how to parse xml on mozilla?
markr
markr
I take it you are aware, that XMLDocument objects load asynchronously by default, as per the doc here

XMLDocument at xulplanet

Therefore, if you're expecting it to load synchronously, you'll have to set the async property to false before calling load.

Or do whatever you have to do with it on its onload event. I'm not completely sure whether you can use .onload to set the onload event, or whether you have to call addEventListener to do it.

Mark
EvilCrap
EvilCrap
ok what i needed was an xmldoc.async=false for the moz segment, in the examples i found this was only in the ie segment.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.