Using ruby 1.9.3 and Nokogiri (latest):
Given (no, I did not come up with this):
<root>
<subelement>
<key>
<var name="id">50</var>
<var name="secondaryid">0</var>
</key>
</subelement>
<subelement>
<key>
<var name="id">50</var>
<var name="secondaryid">1</var>
</key>
</subelement>
</root>
Return the parent element (<key>) which has a var element with name property equal to “id” and a value equal to 50 AND a var element with name property equal to “secondaryid” and a value equal to 0. Do not return the node with id=50 and secondaryid=1.
Obviously it’s going to be built off something along the lines of:
@doc.xpath(“//var[@name=’id’ and text()=50]”)
but I can’t figure out how to add another predicate that will match the name = “secondaryid” element too.
Not tested with Ruby, but this should do the trick.