By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,605 Members | 2,147 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,605 IT Pros & Developers. It's quick & easy.

question about javascript with XML

P: n/a
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.
Jul 18 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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/
Jul 19 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.