3.2.2010, JavaScript, Tutorials By Patrick
0
XML is a huge part of AJAX, considering that AJAX is an acronym for Asynchronous JavaScript and XML. jQuery is no doubt one of the most powerful and popular JavaScript libraries out there. jQuery has made parsing XML a lot easier, faster, and cleaner.
The XML
The XML that I’m going to parse is a small phonebook with three people in it. Each person has a name, email, phone number, and an address. We are going to read in the information of each person and display them. To find out more about XML syntax see W3School’s XML Syntax.
<?xml version="1.0"?> <phonebook> <person> <name>Joe A. Doyle</name> <email>joe@example.com</email> <phone_number>901-795-3338</phone_number> <address>3102 Burton Avenue Memphis, TN 38118</address> </person> <person> <name>Michael D. Montgomery</name> <email>MichaelDMontgomery@example.com</email> <phone_number>907-793-5822</phone_number> <address>3295 Kidd Avenue Anchorage, AK 99501</address> </person> <person> <name>Linda D. Serrano</name> <email>LindaDSerrano@example.com</email> <phone_number>978-793-2440</phone_number> <address> 3725 Christie Way Westborough, MA 01581</address> </person> </phonebook>
Getting Start with jQuery
Let’s start off by including jQuery into our page.
Before we have jQuery parse the XML we need to make sure the DOM (Document Object Model) is loaded. We do this by simply adding the following code.
$(document).ready(function(){
//Everything will go inside here…
});