1

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

1
  • I guess file.getElementsByName("bank")[0].getElementById(/*the id*/).nodeValue shoud work. Commented Jul 11, 2011 at 0:26

2 Answers 2

1

try file.getElementById('2')?

Also why don't use use JSON instead..

Sign up to request clarification or add additional context in comments.

1 Comment

I'm not aware of how browser handle it, but normaly getElementById() should not work on a XML-structure without a known namespace because it is unclear which attribute is an ID. Normally it is declared in the DTD.
1
file.getElementsByTagName('money')[2].firstChild.nodeValue

The first Child of <money> is a textnode.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.