DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Use Texts To Find All Text Elements

  • submit to reddit
        REXML::Element::texts returns all text elements within a leaf node.
doc_b ="<root><a>\n<b>333</b>  <c/>  456</a></root>")
#=> <UNDEFINED> ... </>
irb(main):434:0> doc_b.root.elements['a'].text
#=> "\n"
irb(main):433:0> doc_b.root.elements['a'].texts
#=> ["\n", "  ", "  456"]

I discovered this while browsing <a href="">Use has_elements to find children in REXML</a> []