Eric
Eric

Reputation: 11

How to read this xml file with javascript?

Im reading an XML file with ajax. Everything is working, I have just no idea how to get the string out of the xml file. The xml file looks like this:

<file>
    <data>
        <name>Brittus</name>
    </data>
    <bank>
        <money id="1">10</money>
        <money id="2">25</money>
        <money id="3">40</money>
        <money id="4">60</money>
    </bank>
</file>

Now I would like to get the value of the tag money with the attribute 4. How can i get it with javascript?

file = responseObject.responseXML;
alert(file.getElementsbyTagName("money")[2].//an now?

And how to get the value of the money tag with id 2?

Thank you

Upvotes: 1

Views: 1222

Answers (2)

Saxoier
Saxoier

Reputation: 1287

file.getElementsByTagName('money')[2].firstChild.nodeValue

The first Child of <money> is a textnode.

Upvotes: 1

Pwnna
Pwnna

Reputation: 9528

try file.getElementById('2')?

Also why don't use use JSON instead..

Upvotes: 1

Related Questions