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
Use Texts To Find All Text Elements
REXML::Element::texts returns all text elements within a leaf node.
doc_b = Document.new("<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="http://snippets.dzone.com/posts/show/8957">Use has_elements to find children in REXML</a> [dzone.com]





