Method: REXML::Element#each_element_with_text
- Defined in:
- lib/rexml/element.rb
#each_element_with_text(text = nil, max = 0, name = nil, &block) ⇒ Object
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
Elementchildren that contain at least oneTextnode. - 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>b</b><c>b</c><d>d</d><e/></a>'
# 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}
382 383 384 385 386 387 388 389 390 |
# File 'lib/rexml/element.rb', line 382 def each_element_with_text( text=nil, max=0, name=nil, &block ) # :yields: Element each_with_something( proc {|child| if text.nil? child.has_text? else child.text == text end }, max, name, &block ) end |