Class Nokogiri::XML::Reader
In: lib/nokogiri/ffi/xml/reader.rb
lib/nokogiri/xml/reader.rb
ext/nokogiri/html_document.c
Parent: Object

Nokogiri::XML::Reader parses an XML document similar to the way a cursor would move. The Reader is given an XML document, and yields nodes to an each block.

Here is an example of usage:

  reader = Nokogiri::XML::Reader(<<-eoxml)
    <x xmlns:tenderlove='http://tenderlovemaking.com/'>
      <tenderlove:foo awesome='true'>snuggles!</tenderlove:foo>
    </x>
  eoxml

  reader.each do |node|

    # node is an instance of Nokogiri::XML::Reader
    puts node.name

  end

Note that Nokogiri::XML::Reader#each can only be called once!! Once the cursor moves through the entire document, you must parse the document again. So make sure that you capture any information you need during the first iteration.

The Reader parser is good for when you need the speed of a SAX parser, but do not want to write a Document handler.

Methods

Included Modules

Enumerable

Attributes

encoding  [R]  The encoding for the document
errors  [RW]  A list of errors encountered while parsing
source  [R]  The XML source

Public Class methods

Public Instance methods

Get the number of attributes for the current node

Get a list of attributes for this Node

Get a list of attributes for the current node.

Does this node have attributes?

Was an attribute generated from the default value in the DTD or schema?

Get the depth of the node

Move the cursor through the document yielding each node to the block

Get the xml:lang scope within which the node resides.

Get the local name of the node

Get the name of the node

Get the URI defining the namespace associated with the node

Get a hash of namespaces for this Node

Get the shorthand reference to the namespace associated with the node.

Move the Reader forward through the XML document.

Get the state of the reader

Get the text value of the node if present

Does this node have a text value?

Get the XML version of the document being read

[Validate]