Page 1 of 1

Running through the XML tree...

Posted: Tue Dec 30, 2003 4:04 pm
by Gen-ik
I've just started using XML today so go easy on me (aohah I'm a newbie again!)

Anyway, I'm using the xmldom object to read XML files into JavaScript and I'm having trouble spliting up the info.

Here's what I've got...

XML

Code: Select all

<?xml version="1.0" encoding="ISO-8859-1" ?>

<modules>

    <unit>
        <name>Xtron</name>
        <type>distortion</type>
        <position>2,10</position>
    </unit>

    <unit>
        <name>SubTronix</name>
        <type>bass</type>
        <position>7,13</position>
    </unit>

</modules>
JAVASCRIPT

Code: Select all

var xmlDoc=new ActiveXObject("microsoft.xmldom")
xmlDoc.async="false"
xmlDoc.load("modulelib.xml")

var nodes = xmlDoc.documentElement.childNodes

var nameA = nodes.item(0).text
var typeA = nodes.item(1).text
var positionA = nodes.item(2).text

That sort of works but I'm getting both of the unit names (Xtron and SubTronix) added to the nameA variable and I'm not sure how to get them individually.

Any help would be cool.

Posted: Tue Dec 30, 2003 4:43 pm
by Gen-ik
No problem I've just worked it out :)