views:

138

answers:

1

Using jquery is it possible to filter XML results that are loaded? Ideally i would like to do a mysql style filer/search 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?

+1  A: 

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() });
Doug Neiner