From: Robert Klemme Date: 2012-12-17T17:11:41+09:00 Subject: Re: print - and strip text between tags using Nokogiri On Sun, Dec 16, 2012 at 11:18 AM, 7stud -- wrote: > Robert Klemme wrote in post #1089225: >> >> puts dom.xpath('/html/body//pre/text()').map(&:to_s) > > Calling map() is redundant because puts calls to_s on its arguments. Right, thanks for the reminder! That was an artifact of IRB testing. :-) >> 2) to print all of the non-tagged text between the >> "body" comments > > Your html doesn't even test your requirements because there is no text > after the body="end' comment. And there is no non-tagged text: I overlooked the comment thing. #!/usr/bin/ruby require 'nokogiri' # require 'irb' text = < My Title

My Heading

From:Me
Date: Wed Dec 05 2012 - 18:17:49 EST

text line 1
text line 2
text line 3

very important text
more important text
would you believe even more important text?

not to print HTML dom = Nokogiri.HTML(text) puts dom.xpath('/html/body//pre/text()') puts '---' puts dom.xpath('//text()[contains(preceding::comment(),"start") and contains(following::comment(),"end") and not(ancestor::pre)]') Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/