Install
sudo gem install nokogiri
Contribute
github.com/tenderlove/nokogiri

An HTML, XML, SAX, & Reader parser with the ability to search documents via XPath or CSS3 selectors… and much more

Nokogiri

Class Nokogiri::HTML::DocumentFragment inherits from Nokogiri::XML::DocumentFragment

Public Class Methods

new(document, tags = nil, ctx = nil) Show Source
# File lib/nokogiri/html/document_fragment.rb, line 12 12: def initialize document, tags = nil, ctx = nil 13: return self unless tags 14: 15: children = if ctx 16: ctx.parse("<div>#{tags.strip}</div>").first.children 17: else 18: ### 19: # This is a horrible hack, but I don't care 20: if tags.strip =~ /^<body/ 21: path = "/html/body" 22: else 23: path = "/html/body/node()" 24: end 25: 26: HTML::Document.parse( 27: "<html><body>#{tags.strip}</body></html>", 28: nil, 29: document.encoding 30: ).xpath(path) 31: end 32: children.each { |child| child.parent = self } 33: end
parse(tags) Show Source
  

Create a Nokogiri::XML::DocumentFragment from tags

# File lib/nokogiri/html/document_fragment.rb, line 6 6: def self.parse tags 7: doc = HTML::Document.new 8: doc.encoding = 'UTF-8' 9: new(doc, tags) 10: end