each_element_with_text( text=nil, max=0, name=nil ) public

Iterates through the children, yielding for each Element that has a particular text set.

text

the text to search for. If nil, or not supplied, will iterate over all Element children that contain at least one Text node.

max

(optional) causes this method to return after yielding for this number of matching children

name

(optional) if supplied, this is an XPath that filters the children to check.

doc = Document.new ‘<a>b<c>b</c><d>d</d><e/>’ # Yields b, c, d doc.each_element_with_text {|e|p e} # Yields b, c doc.each_element_with_text(‘b’){|e|p e} # Yields b doc.each_element_with_text(‘b’, 1){|e|p e} # Yields d doc.each_element_with_text(nil, 0, ‘d’){|e|p e}

Show source
Register or log in to add new notes.