question about javascript with XML

H

harry.webber722

Hi there,
I have an XML string which I would like to extract some data from. Is
there any way I can do that?
For example, the XML data is as follows:
<student>
<name>Harry</name>
<result>
<subject>Math</subject>
<score>90</score>
</result>
<result>
<subject>Literature</subject>
<score>78</score>
</result>
</student>

Is there any way I can use javascript to extract the name and each of
the subject and score?
I can then use the values to display on a table using dynamic HTML
which I know how to do.
I just don't know how to handle the XML.

Thanks.
 
M

Marc

Hi there,
I have an XML string which I would like to extract some data from. Is
there any way I can do that?
For example, the XML data is as follows:
<student>
<name>Harry</name>
<result>
<subject>Math</subject>
<score>90</score>
</result>
<result>
<subject>Literature</subject>
<score>78</score>
</result>
</student>

Is there any way I can use javascript to extract the name and each of
the subject and score?
I can then use the values to display on a table using dynamic HTML
which I know how to do.
I just don't know how to handle the XML.

Thanks.

You could use the following xml2json converter:
http://www.thomasfrank.se/xml_to_json.html

var json=xml2json.parser(myXML);
alert( json['student']['name'] ); //harry
alert( json['student']['result'][0]['subject'] ); //Math

This json editor might come in handy:
http://braincast.nl/samples/jsoneditor/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,142
Messages
2,570,818
Members
47,362
Latest member
eitamoro

Latest Threads

Top