Skip to content

Instantly share code, notes, and snippets.

@aruprakshit
Created February 11, 2015 06:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aruprakshit/47ce52832b716b5eda55 to your computer and use it in GitHub Desktop.
Save aruprakshit/47ce52832b716b5eda55 to your computer and use it in GitHub Desktop.
difference between Nokogiri::HTML::DocumentFragment and Nokogiri::HTML::Document
require 'nokogiri'
doc = Nokogiri::HTML::Document.parse <<-html
<table style="width:100%">
<tr>
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
</table>
html
puts doc.xpath("//table/tr").count # 2
require 'nokogiri'
doc = Nokogiri::HTML::DocumentFragment.parse <<-html
<table style="width:100%">
<tr>
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
</table>
html
puts doc.xpath("//table/tr").count # 0
@aruprakshit
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment