Running through the XML tree...

XML, Perl, Python, and other languages can be discussed here, even if it isn't PHP (We might forgive you).

Moderator: General Moderators

Post Reply
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Running through the XML tree...

Post 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.
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post by Gen-ik »

No problem I've just worked it out :)
Post Reply