XML::Reader
XML::Reader is a parser for XML that iterates a XML document.
require "xml"
reader = XML::Reader.new(<<-XML)
<message>Hello XML!</message>
XML
reader.read
reader.name # => "message"
reader.read
reader.value # => "Hello XML!"
This is an alternative approach to XML.parse which parses an entire document
into an XML data structure.
XML::Reader offers more control and does not need to store the XML document
in memory entirely. The latter is especially useful for large documents with
the IO-based constructor.
WARNING: This type is not concurrency-safe.
Constructors
Creates a new reader from a string.
See XML::ParserOptions.default for default options.
Creates a new reader from an IO.
See XML::ParserOptions.default for default options.
Instance methods
Gets the attribute content for the attribute given by name.
Raises KeyError if attribute is not found.
Gets the attribute content for the attribute given by name.
Returns nil if attribute is not found.
Expands the node to a XML::Node that can be searched with XPath etc.
The returned XML::Node is only valid until the next call to #read.
Raises a XML::Error if the node could not be expanded.
Expands the node to a XML::Node that can be searched with XPath etc.
The returned XML::Node is only valid until the next call to #read.
Returns nil if the node could not be expanded.
Moves to the XML::Reader::Type::ATTRIBUTE with the specified name.
Moves from the XML::Reader::Type::ATTRIBUTE to its containing XML::Reader::Type::ELEMENT.