Friday 10 July 2009

jQuery - Searching XML

Earlier I discussed how to remove a node based on your search criteria, I will now go over briefly the different methods to select specified nodes from your XML with jQuery.

Basic selection:

var people = $(xml).find("person");


This will select all nodes with the name of "person".

Selection where attribute exists:

var people = $(xml).find("person").attr("id");


This will select all nodes with the name of "person" but which also have an attribute with the name of "id".

Selection based on attribute value:

var people = $(xml).find("person[id='1']");


This will select all nodes with the name of "person" but which also have an attribute with the name of "id" which in turn has a value of "1".

No comments: