Class: Badgerhash::Parsers::REXML::SaxDocument Private

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
REXML::StreamListener
Defined in:
lib/badgerhash/parsers/rexml.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

SaxDocument provides an implmentation of the required public interface for a parser that is to be used when parsing an XmlStream. An implementation is required to provide a parse method that accepts a Badgerhash::Handler::SaxHandler and an IO object. When parsing the given IO stream, it must send messages to the handler in order to build the correct Hash. This also serves as a reference implementation for other sax parsers.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(handler) ⇒ SaxDocument

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initialize the parser.

Parameters:



36
37
38
# File 'lib/badgerhash/parsers/rexml.rb', line 36

def initialize(handler)
  @handler = handler
end

Class Method Details

.parse(handler, io) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parse the given stream and update the handler.

Parameters:

  • handler (Badgerhash::Handler::SaxHandler)

    parsing handler

  • io (IO)

    the XML to be parsed.

Returns:

  • void



29
30
31
# File 'lib/badgerhash/parsers/rexml.rb', line 29

def self.parse(handler, io)
  ::REXML::Document.parse_stream(io, new(handler))
end

Instance Method Details

#tag_start(name, attributes = []) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



40
41
42
43
44
45
# File 'lib/badgerhash/parsers/rexml.rb', line 40

def tag_start(name, attributes=[])
  @handler.start_element name
  Array(attributes).each do |attr|
    @handler.attr(*attr)
  end
end