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::XML::DocumentFragment inherits from Nokogiri::XML::Node

Public Class Methods

new(document, tags=nil) Show Source
# File lib/nokogiri/xml/document_fragment.rb, line 4 def initialize document, tags=nil if tags if self.kind_of?(Nokogiri::HTML::DocumentFragment) HTML::SAX::Parser.new(FragmentHandler.new(self, tags)).parse(tags) else wrapped = "<div>#{tags.strip}</div>" XML::SAX::Parser.new(FragmentHandler.new(self, wrapped)).parse(wrapped) div = self.child div.children.each { |child| child.parent = self } div.unlink end end end
new(...) Show Source

Create a new DocumentFragment element on the document

static VALUE new(int argc, VALUE *argv, VALUE klass) { xmlDocPtr xml_doc; VALUE document; VALUE rest; rb_scan_args(argc, argv, "1*", &document, &rest); Data_Get_Struct(document, xmlDoc, xml_doc); xmlNodePtr node = xmlNewDocFragment(xml_doc->doc); NOKOGIRI_ROOT_NODE(node); VALUE rb_node = Nokogiri_wrap_xml_node(klass, node); rb_obj_call_init(rb_node, argc, argv); if(rb_block_given_p()) rb_yield(rb_node); return rb_node; }
parse(tags) Show Source

Create a Nokogiri::XML::DocumentFragment from tags

# File lib/nokogiri/xml/document_fragment.rb, line 66 def parse tags self.new(XML::Document.new, tags) end

Public Instance Methods

css(*args) Show Source

Search this fragment. See Nokogiri::XML::Node#css

# File lib/nokogiri/xml/document_fragment.rb, line 53 def css *args if children.any? children.css(*args) else NodeSet.new(document) end end
name() Show Source

return the name for DocumentFragment

# File lib/nokogiri/xml/document_fragment.rb, line 20 def name '#document-fragment' end
serialize()

Alias for to_s

to_html(*args) Show Source

Convert this DocumentFragment to html See Nokogiri::XML::NodeSet#to_html

# File lib/nokogiri/xml/document_fragment.rb, line 33 def to_html *args children.to_html(*args) end
to_s() Show Source

Convert this DocumentFragment to a string

# File lib/nokogiri/xml/document_fragment.rb, line 26 def to_s children.to_s end
to_xhtml(*args) Show Source

Convert this DocumentFragment to xhtml See Nokogiri::XML::NodeSet#to_xhtml

# File lib/nokogiri/xml/document_fragment.rb, line 40 def to_xhtml *args children.to_xhtml(*args) end
to_xml(*args) Show Source

Convert this DocumentFragment to xml See Nokogiri::XML::NodeSet#to_xml

# File lib/nokogiri/xml/document_fragment.rb, line 47 def to_xml *args children.to_xml(*args) end