jQuery

Process Each Node Of XML In JQuery

JQuery is a very useful tool to use to loop through elements, this is because of the each function. It will loop through each of the elements it has in the jQuery object, this can be a HTML dom element, or multiple elements or in this example is xml nodes.

JQuery can load a file of XML and loop through by using 2 built-in jQuery functions the .get function and the each function. First you use the .get function to get all elements of the XML. Just pass the location of the file as the first parameter then inside this function you can use the xml variable.

$.get("xmlfile.xml", {}, function (xml) {

}

Inside this function you can use the xml variable to process the xml nodes.

Now create a jQuery object search for the name of the node you want 'node' with the XML document and process each one of the nodes.

$('node', xml).each(function (i) {
        //Do something
});

Full Code

//Load xml file
$.get("xmlfile.xml", {}, function (xml) {
     //Loop through each node
     $('node', xml).each(function (i) {
        //Do something
     });
}):
Back to top ^

Join Paulund

  • Get access to 100s of premium tutorials and downloadable content
  • Members content consists of Premium WordPress plugins, CSS packages, jQuery packages, tutorial demo files and templates for 100s of web development tutorials
  • In-depth development tutorials
  • Priority tutorial requests
  • Priority email development support
  • No ads

Here at Paulund you'll find Web Development tutorials and snippets focusing mainly on PHP, WordPress and CSS. Members will get access to premium tutorials that go into more detail about development with these languages. You will also get access to downloadable premium content based on the tutorial.

Join Paulund

Leave a Reply

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