From: Phrogz Date: 2007-03-19T23:25:10+09:00 Subject: Re: Pulling text from elements with REXML On Mar 19, 8:04 am, "Phrogz" wrote: > On Mar 19, 5:38 am, Paul Willis wrote: > > > root.elements["NewsItem/NewsComponent/NewsComponent[1]/NewsComponent/Conten tItem/DataContent/nitf/body/body.head/hedline/hl1"] > > > Gives me... > > > Blueprint to cut emissions unveiled > > > Is there an easy way (ie something in REXML) to pull just the text > > without the containers and . > > require 'rexml/document' > doc = REXML::Document.new("hello world") > p REXML::XPath.first( doc, '/root/kid/text()' ) > #=> "hello world" Also, depending on your needs: include REXML doc = Document.new("helloworld") p XPath.match( doc, '/root/kid/text()' ) #=> ["hello", "world"]