jQuery查询XML文档where子句 [英] Jquery query XML document where clause
本文介绍了jQuery查询XML文档where子句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个XML文档,我想搜索一个特定的日期并获取该日期的信息.我的XML看起来像这样:
I have an XML document that I want to search a specific date and get information for just that date. My XML looks like this:
<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看起来像这样:
My Jquery looks like this:
$(xml).find('month[id=01]').each(function()
{
$(xml).find("day").each(function()
{
var day = $(this).attr('id');
alert(day);
});
});
在上面的XML示例中,我只显示了一个月,但是还有更多. 在我的JQuery中,我尝试执行凡月= 1"并获取该月的所有天数信息,但是JQuery会带回每个月的天数.如何在XML文档上使用JQuery/JavaScript执行where子句?谢谢.
In the XML example above I only shown one month, however there are many more. In my JQuery I've tried to do 'Where month = 1' and get all the days info for that month, however that JQuery brings back days for every month. How do I do a where clause with JQuery/JavaScript on a XML document? thanks.
推荐答案
$(xml).find('month[id=01]').each(function()
{
$(this).find("day").each(function()
// ^^^^
{
var day = $(this).attr('id');
alert(day);
});
});
这篇关于jQuery查询XML文档where子句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文