Filtering XML results using jquery
Using jquery is it possible to filter XML results that are loaded? Ideally i would like to do a mysql style filer/se开发者_开发知识库arch like
SELECT * FROM "example_table" WHERE id="1"
I have an XML file loaded in to my application with the following structure
<country>
<state id="1">
<statename>Baden-Wurttemberg</statename>
<cities>
<city>
<cityname>Aach</cityname>
<yahoo>1</yahoo>
</city>
Aalen 2 I have multiple states (each with an "id") within my COUNTRY tag. How can i get all cities from state with id="1" using jquery?
You wouldn't be able to use MySQL syntax without a plugin (if one exists), but you can just use jQuery selectors, then use map to turn it into a JS array of the cities:
var cities = $(xml).find('state[id=1] cityname')
.map(function(i,el){ return $(el).text() });
精彩评论