check xml for node that doesn't exist with jQuery?
I have an XML doc that looks similar to:
<schedule techs="52" date="2009-10-06">
<tech name="Ryan (RI, MA, CT, NH)" value="1">
<time value="4">
&l开发者_如何学运维t;HONAME value="Ronald Baron"/>
<ADDRESS value="35 Liepis rd"/>
<CITY value="Canterbury"/>
<STATE value="CT"/>
<ZIP value="06331"/>
<JOBNUMBER value="33028"/>
<RESULT value="C"/>
<NOTES value=""/>
<BOARD value=""/>
</time>
<time value="9-1">
<HONAME value="Howard McFadzen"/>
<ADDRESS value="77 Crown St. Extension"/>
<CITY value="Meriden"/>
<STATE value="CT"/>
<ZIP value="06450"/>
<JOBNUMBER value="9188"/>
<RESULT value=""/>
<NOTES value="Close ticket 10097792 System keeps sending RF interference and receiver tamper, please fix"/>
<BOARD value="10-1 please"/>
</time>
</tech>
</schedule>
How do I use JavaScript/jQuery to test for empty nodes? I need to be able to check for several times and if a certain time node such as 1-5 isn't in the XML, I need to run a different function. Any ideas?
Try using the attribute equals selector
if($('time[value=1-5]').length > 0)
{
// time 1-5 exists
funcA();
}
else
{
// time 1-5 doesn't exists
funcB();
}
精彩评论