jQuery Makes Parsing XML Easy

jQuery scroll to element

jQuery.parseXML uses native parsing function of the browser to create a valid XML document.

After that this document can then be passed to jQuery for creating a typical jQuery object which can be traversed and manipulated then.

This is a easy technique of parsing JSON with jQuery and thought i’d pick this up and show you how to parse XML. It is available from jQuery 1.5 version.

Here is the XML code for the purpose of the demo.

var xml = "<note><heading>Sample Heading</heading><body>Hi! Is this the body you are looking for?</body></note>";
xmlDoc = $.parseXML( xml );
$xml = $( xmlDoc );
$body = $xml.find( "body" );

You will get the result: Hi! Is this the body you are looking for?

Get more details from jQuery reference.

Leave a Reply

Your email address will not be published. Required fields are marked *