Method: Nokogiri::XML::Node#prepend_child
- Defined in:
- lib/nokogiri/xml/node.rb
#prepend_child(node_or_tags) ⇒ Object
Add node_or_tags
as the first child of this Node.
node_or_tags
can be a Nokogiri::XML::Node, a ::DocumentFragment, a ::NodeSet, or a String containing markup.
Returns the reparented node (if node_or_tags
is a Node), or NodeSet (if node_or_tags
is a DocumentFragment, NodeSet, or String).
Also see related method add_child
.
204 205 206 207 208 209 210 211 212 213 |
# File 'lib/nokogiri/xml/node.rb', line 204 def prepend_child() if (first = children.first) # Mimic the error add_child would raise. raise "Document already has a root node" if document? && !(.comment? || .processing_instruction?) first.__send__(:add_sibling, :previous, ) else add_child() end end |