Popular Articles
List of Useful jQuery Plugins
jQuery Makes Parsing XML Easy
Installing Subversion on Apache
SVN Authentication and Auto Update
jQuery Plugin Actions vs Utilities
Create a Blog from Scratch
Interviewed by Google
Tags
jQuery Makes Parsing XML Easy
JQuery, JavaScript, XML
I am building a Google Maps project and jQuery is making my life so much easier when parsing XML.
Regular JavaScript XML Parsing
var xmlDoc = request.responseXML;
try // Build Markers, if available
{
var markers = xmlDoc.getElementsByTagName("marker") ;
for ( var i = 0; i < markers.length ; i++ )
{
var point = {
markers[i].getAttribute("lat")),
markers[i].getAttribute("lng")
};
}
} catch(e) {}
jQuery XML Parsing
$(request.responseXML).find("marker").each(function() {
var marker = $(this);
var point = {
marker.attr("lat"),
marker.attr("lng")
};
});
The jQuery code is so much easier to read and understand. This is a basic example, but imagine when things get complex. After writing a few complex statements, you will realize the jQuery code will still be understandable, where as the JavaScript code will become hard to maintain. Thank you jQuery for making my job easier and more fun.
#1. Forrest on Nov 07 2007
Wow! *quickly re-writes own code excitedly*
#2. Ryan on Nov 07 2007
One of the best things about ActionScript 3 is E4X syntax where this stuff is really easy. I'm looking forward to when JavaScript gets that upgrade and no JavaScript trickery is needed.
#3. Marc on Nov 07 2007
Until then, jQuery is our upgrade to JavaScript. And it does a dang good job at it.
#4. yitz on Dec 25 2007
thanks, this post was the decisive one in helping me to achieve successful xml parsing in jquery.. it was the perfect tutorial :)
#5. Mustafa on Mar 22 2008
thank for good view about jquery, I will start it using