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.


>
> 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:


require 'nokogiri'

html = <<HTML
<html>
<head>
<title>My Title</title>
</head>
<body>
<h1>My Heading</h1>
<strong>From:</strong>Me<br>
<strong>Date:</strong> Wed Dec 05 2012 - 18:17:49 EST
<!-- body="start" -->
<p>
text line 1
<br>
text line 2
<br>
text line 3
<br>
<p><pre>
very important text
more important text
would you believe even more important text?
</pre>
<p><!-- body="end" -->
<p>
text line 4
<br>
text line 5
</body>
</html>
HTML


doc = Nokogiri.HTML(html)

my_xpath = "/html/body/comment()[1]/following-sibling::*"

doc.xpath(my_xpath).each do |node|
  puts node.name
  puts node.text
  puts '*' * 20
end

--output:--
p

text line 1

text line 2

text line 3
********************
p

********************
pre

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

********************
p

text line 4

text line 5
********************


--output:--
text line 1
text line 2
text line 3



doc = Nokogiri.HTML(html)

my_xpath = 
"/html/body/comment()[1]/following-sibling::*[not(self::pre)]"

catch :found_ending_text do
  doc.xpath(my_xpath).each do |node|
    node.children.each do |child|
      text = child.text
      throw :found_ending_text if text.include? %q{body}
      next if text.empty?
      puts text.strip
    end
  end
end


--output:--
text line 1
text line 2
text line 3

-- 
Posted via http://www.ruby-forum.com/.