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

The Reader parser allows you to effectively pull parse an XML document. Once instantiated, call Nokogiri::XML::Reader#each to iterate over each node. Note that you may only iterate over the document once!

### Methods

attr_nodes attribute attribute_at attribute_count attribute_nodes attributes attributes? base_uri default? depth each empty_element? from_io from_memory inner_xml lang local_name name namespace_uri namespaces node_type outer_xml prefix read state value value? xml_version

### Included Modules

Enumerable

### Constants

TYPE_NONE | = | 0
TYPE_ELEMENT | = | 1 |  | Element node type
TYPE_ATTRIBUTE | = | 2 |  | Attribute node type
TYPE_TEXT | = | 3 |  | Text node type
TYPE_CDATA | = | 4 |  | CDATA node type
TYPE_ENTITY_REFERENCE | = | 5 |  | Entity Reference node type
TYPE_ENTITY | = | 6 |  | Entity node type
TYPE_PROCESSING_INSTRUCTION | = | 7 |  | PI node type
TYPE_COMMENT | = | 8 |  | Comment node type
TYPE_DOCUMENT | = | 9 |  | Document node type
TYPE_DOCUMENT_TYPE | = | 10 |  | Document Type node type
TYPE_DOCUMENT_FRAGMENT | = | 11 |  | Document Fragment node type
TYPE_NOTATION | = | 12 |  | Notation node type
TYPE_WHITESPACE | = | 13 |  | Whitespace node type
TYPE_SIGNIFICANT_WHITESPACE | = | 14 |  | Significant Whitespace node type
TYPE_END_ELEMENT | = | 15 |  | Element end node type
TYPE_END_ENTITY | = | 16 |  | Entity end node type
TYPE_XML_DECLARATION | = | 17 |  | XML Declaration node type

### External Aliases

empty_element? | -> | self_closing?

### 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

from_io(io, url = nil, encoding = nil, options = 0)

Create a new reader that parses `io`

from_memory(string, url = nil, encoding = nil, options = 0)

Create a new reader that parses `string`

### Public Instance methods

attribute_nodes

Get a list of attributes for this Node

attribute(name)

Get the value of attribute named `name`

attribute_at(index)

Get the value of attribute at `index`

attribute_count

Get the number of attributes for the current node

attribute_nodes()

Get a list of attributes for the current node

attributes()

Get a list of attributes for the current node.

attributes?

Does this node have attributes?

base_uri

Get the xml:base of the node

default?

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

depth

Get the depth of the node

each() {|cursor| ...}

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

reader.empty_element? # => true or false

Returns true if the current node is empty, otherwise false.

inner_xml

Read the contents of the current node, including child nodes and markup. Returns a utf-8 encoded string.

lang

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

local_name

Get the local name of the node

name

Get the name of the node. Returns a utf-8 encoded string.

namespace_uri

Get the URI defining the namespace associated with the node

namespaces

Get a hash of namespaces for this Node

node_type

Get the type of readers current node

outer_xml

Read the current node and its contents, including child nodes and markup. Returns a utf-8 encoded string.

prefix

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

read

Move the Reader forward through the XML document.

state

Get the state of the reader

value

Get the text value of the node if present. Returns a utf-8 encoded string.

value?

Does this node have a text value?

xml_version

Get the XML version of the document being read

[Validate]