Jquery查询XML文档where子句

时间:2011-01-17 10:49:34

标签: jquery xml where-clause

我有一个XML文档,我想搜索特定日期并获取该日期的信息。我的XML看起来像这样:

    <month id="01">
        <day id="1">
            <eitem type="dayinfo">
                <caption>
                    <text lang="cy">f. 3 r.</text>
                    <text lang="en">f. 3 r.</text>
                </caption>
                <ref href="link" id="3"/>
                <thumb href="link" id="3"/>
            </eitem>
        </day>
        <day id="7">
            <eitem type="dayinfo">
                <caption>
                    <text lang="cy">f. 5 v.</text>
                    <text lang="en">f. 5 v.</text>
                </caption>
                <ref href="link" id="4"/>
                <thumb href="link" id="4"/>
            </eitem>
        </day>
        <day id="28">
            <eitem type="dayinfo2">
                <caption id="1">
                    <text lang="cy">test</text>
                    <text lang="en">test2</text>
                </caption>
                <ref href="link" id="1"/>
                <thumb href="link" id="1"/>
            </eitem>
        </day>
        <day id="28">
            <eitem type="dayinfo">
                <caption>
                    <text lang="cy">f. 14 v.</text>
                    <text lang="en">f. 14 v.</text>
                </caption>
                <ref href="link" id="20"/>
                <thumb href="link" id="20"/>
            </eitem>
        </day>
    </month>

我的Jquery看起来像这样:

            $(xml).find('month[id=01]').each(function()
            {
                $(xml).find("day").each(function()
                {
                    var day = $(this).attr('id');
                    alert(day);
                });
            });

在上面的XML示例中,我只显示了一个月,但还有更多。 在我的JQuery中,我试图做'Where month = 1'并获得该月的所有日期信息,但是JQuery每个月都会带回来。如何在XML文档上使用JQuery / JavaScript执行where子句?感谢。

1 个答案:

答案 0 :(得分:2)

   $(xml).find('month[id=01]').each(function()
        {
            $(this).find("day").each(function()
          //  ^^^^
            {
                var day = $(this).attr('id');
                alert(day);
            });
        });
相关问题