Class Nokogiri::XML::Document
In: lib/nokogiri/xml/document.rb
Parent: Nokogiri::XML::Node

Nokogiri::XML::Document is the main entry point for dealing with XML documents. The Document is created by parsing an XML document. See Nokogiri.XML()

For searching a Document, see Nokogiri::XML::Node#css and Nokogiri::XML::Node#xpath

Methods

External Aliases

serialize -> to_xml
dup -> clone

Attributes

errors  [RW]  A list of Nokogiri::XML::SyntaxError found when parsing a document

Public Class methods

Parse an XML file. thing may be a String, or any object that responds to read and close such as an IO, or StringIO. url is resource where this document is located. encoding is the encoding that should be used when processing the document. options is a number that sets options in the parser, such as Nokogiri::XML::ParseOptions::RECOVER. See the constants in Nokogiri::XML::ParseOptions.

Public Instance methods

<<(child)

Alias for add_child

Recursively get all namespaces from this node and its subtree and return them as a hash.

For example, given this document:

  <root xmlns:foo="bar">
    <bar xmlns:hello="world" />
  </root>

This method will return:

  { 'xmlns:foo' => 'bar', 'xmlns:hello' => 'world' }

WARNING: this method will clobber duplicate names in the keys. For example, given this document:

  <root xmlns:foo="bar">
    <bar xmlns:foo="baz" />
  </root>

The hash returned will look like this: { ‘xmlns:foo’ => ‘bar’ }

Create an element with name

Create a text node with text

Apply any decorators to node

Get the list of decorators given key

A reference to self

Create a Nokogiri::XML::DocumentFragment from tags Returns an empty fragment if tags is nil.

The name of this document. Always returns “document“

Get the hash of namespaces on the root Nokogiri::XML::Node

Explore a document with shortcut methods.

Validate this Document against it’s DTD. Returns a list of errors on the document or nil when there is no DTD.

[Validate]