jQuery.parseXML()S2C Home « Utilities « jQuery.parseXML()

Parsed data to XML document creation.


The jQuery.parseXML() jQuery General utility method, returns an XML document created from the parsed string.

Shorthand version $.parseXML()

  • Creates a valid XML Document from the native parsing function of the browser. The XML document can then be passed to jQuery for creation of a jQuery object.


Signature Description
jQuery.parseXML( data )Return an XML document created from the parsed string.


Parameter Description Type
dataA well-formed XML string to be parsed.String


An XML document.

jQuery.parseXML( data ) Examplego to top of page Top

Return an XML document created from the parsed string.

In the example below when we press the button the first time we parse some well formed XML to a variable and then convert the variable to a jQuery object. After this we iterate over the xml nodes to print out some fictitious diary entries.

  $('#btn21').one('click', function(){
    var xml = "<xml version='1.0'>" +
    "<week date='01/01/2012 '><day activity='shopping '><loc>London</loc></day></week>" +
    "<week date='02/01/2012 '><day activity='driving '><loc>Cardiff</loc></day></week>" +
    "<week date='03/01/2012 '><day activity='eating '><loc>Glasgow</loc></day></week></xml>",
    xmlDoc = $.parseXML( xml ),
    $xml = $( xmlDoc );
    // Print Diary details
    $($xml).find('week').each(function() {
      $('#div17').append($(this).find('loc').text() + "<br />");

div17. Some initial text.

Press the button below to action the above code:

go to home page Homepage go to top of page Top