Find all possible container nodes of a given text

hi,
I’ve been using ruby for a few weeks and been messing with DOM-like
programming
using hpricot.
I’m looking for an efficient (rubyiish) way to find the set of Node
Elements
that have a text_element child containing a given string

for instance given the html code

harr is a dog fuu is a cat jii is a dog

I would like to set this query

getNodesContaining(“dog”)

that would return an Array with the xpath of the first and third td
(since they
contain the text dog)

thanks in advance

Sylvain

well I think I solved it

#!/usr/bin/ruby
require ‘hpricot’

html = <<EOS

harr is a dog fuu is a cat jii is adog
EOS

doc = Hpricot(html)
result=[]
doc.traverse_text do |text|
text_out = text.to_s.strip
if text_out =~ /dog/
result << text.parent.xpath
end
end

thanks anyway

Sylvain

Selon Sylvain T. [email protected]:

I would like to set this query

getNodesContaining(“dog”)

(Hpricot(html)/“//td”).map.reject{ |node| node.inner_text !~ /dog/ }

Cheers,
Peter

__
http://www.rubyrailways.com