Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
87
rated 0 times [  88] [ 1]  / answers: 1 / hits: 155428  / 13 Years ago, mon, august 29, 2011, 12:00:00

How do I parse XML, and how can I navigate the result using jQuery? Here is my sample XML:



<Pages>
<Page Name=test>
<controls>
<test>this is a test.</test>
</controls>
</Page>
<Page Name = User>
<controls>
<name>Sunil</name>
</controls>
</Page>
</Pages>


I would like to find the node by this path Pages -> Page Name -> controls -> test ?


More From » jquery

 Answers
4

There is the $.parseXML function for this: http://api.jquery.com/jQuery.parseXML/


You can use it like this:


var xml = $.parseXML(yourfile.xml),
$xml = $( xml ),
$test = $xml.find('test');

console.log($test.text());

If you really want an object, you need a plugin for that. This plugin for instance, will convert your XML to JSON: http://www.fyneworks.com/jquery/xml-to-json/


[#90373] Friday, August 26, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
reed

Total Points: 725
Total Questions: 85
Total Answers: 89

Location: Singapore
Member since Sat, Jul 25, 2020
4 Years ago
;