+2 votes
asked in java script by (3.1k points)


I have an array that is populated using some xpath; so the items in the array could be as little as 1-20+.

I am populating it like so:

    var masterPath = $('items item', response.responseXML)
    masterPath.each(function (index, obj) {
    var assignments = $('> data > title', obj).text();

However, the xml is a bit different for each, ie




What I need is to only grab the latter two items (the 'data' that contains both a 'duedate' AND an 'availdate'.)

What would be the best way to go through all tags that may exist in the xml, and then only grab the ones with duedates and availdates and put them into the array?

1 Answer

0 votes
answered by (1.1k points)

You want a different selector: http://jsfiddle.net/mKUxw/. This one selects only <data> items which have both a <duedate> and <availdate>:

$("> data:has(duedate):has(availdate) > title", obj)