Parsing XML with jQuery
jQuery itself can be used to parse an XML document on the client side. We can fetch an XML file using jQuery's AJAX methods and then process it on the browser itself and get data from it.
We will recreate the same example that we wrote in the recipe Reading an XML using DOM extension. Contrary to that recipe where we used DOM methods on the server side, we will use jQuery's selector functions to traverse through the XML.
Getting ready
Create a new folder under Chapter3
directory and name it as Recipe7
. Also copy the common.xml
file to this folder.
How to do it...
Create a file named
index.html
in theRecipe7
folder. In this file, simply declare some styles forh1
andul
elements that will be created later through jQuery. Create a DIV element in which we will insert the HTML.<html> <head> <title>Reading xml through jQuery</title></head> <style type="text/css"> h1{ cursor:pointer;font-size:20px;} ul{ display:none...