I have a document and want to extract a couple of elements which ar direct descendents of the parent element but leave out others. The problem is that I don't get the elements in the order they appear in the document. The reason might actually be that the CSS selector I am using is wrong...
require 'rubygems'
require 'nokogiri'
require 'open-uri'
html = <<END
<content>
<p>Lorem</p>
<div>
FOO
<p>BAR</p>
</div>
<h1>Ipsum</h1>
<p>Dolor</p>
<div>
BAR
<h2>FOO</h2>
</div>
<h2>Sit</h2>
<p>Amet</p>
</html>
END
Nokogiri::HTML(html).css('content > p, content > h1, content > h2').inner_html # "<p>Lorem</p><p>Dolor</p><p>Amet</p><h1>Ipsum</h1><h2>Sit</h2>"
What I want is
<p>Lorem</p><h1>Ipsum</h1><p>Dolor</p><h2>Sit</h2><p>Amet</p>