开发者

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜