+2 votes
51 views
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();
    courseHwork.push(assignments);

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

<data>
  <title>example</title>
</data>

<data>
  <title>example2</title>
  <duedate>03-21-12</duedate>
</data>

<data>
  <title>example3</title>
  <duedate>05-02-12</duedate>
  <availdate>04-01-12</availdate>
<data>

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)

Categories

...