From: Peter Szinek Date: 2007-03-19T20:50:20+09:00 Subject: Re: Pulling text from elements with REXML Paul Willis wrote: > Hi > > I am using REXML to pull text from a NewsML document. > > require 'rexml/document' > include REXML > file = File.new("Main_News.xml") > doc = Document.new(file) > root = doc.root > puts > root.elements["NewsItem/NewsComponent/NewsComponent[1]/NewsComponent/ContentItem/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 . If I understood correctly, you need the text content of the node rather than the whole node. This can be accomplished with: some_element.text so you could do something like root.elements[...your stuff_here...].to_a.each {|e| puts e.text} HTH, Peter __ http://www.rubyrailways.com :: Ruby and Web2.0 blog http://scrubyt.org :: Ruby web scraping framework http://rubykitchensink.ca/ :: The indexed archive of all things Ruby