How to match the brother of a certain XML element in ruby?
I played around with nokogiri in ruby and the XML searching feature, e.g.:
a = Nokogiri.XML(open 'a.xml') x = a.search('//div[@class="foo"]').text
which works quite nice.
But how can I specify to match the next (brother) element on the same level (and only the next)?
For example for this input:
<div> <div>...</div> <div>...</div> <div class="foo"></div> <div>EXTRACT ME</dev> ... </div>
The actual input is some non-XHTML html, but so far Nokogiri.XML does not complain.
Btw, what filter syntax f.search actually expects? xpath?
Taking the hint from Brian Agnew and DevNull I guess that f.search actually expects xpath syntax and using the following-sibling predicate the following expression matches what was asked:
a = x.search('//div[@class="foo"]/following-sibling::div')
I think you want XPath's following-sibling predicate.