Class: MultiXML::Parsers::Ox::Handler Private
- Inherits:
-
Object
- Object
- MultiXML::Parsers::Ox::Handler
- Defined in:
- lib/multi_xml/parsers/ox.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.
SAX event handler that builds a hash tree while parsing.
Ox's SAX callbacks expose element and attribute names in prefixed form (e.g. "atom:feed"). Under :preserve we keep the source form verbatim; under :strip we drop the prefix and filter xmlns declarations out of the attribute stream.
Instance Method Summary collapse
-
#attr(name, value) ⇒ void
private
Handle an attribute.
-
#end_element(_name) ⇒ void
private
Handle end of an element.
-
#error(message, line, column) ⇒ void
private
Handle parse errors.
-
#initialize(mode) ⇒ Handler
constructor
private
Create a new SAX handler.
-
#result ⇒ Hash
private
Get the parsed result.
-
#start_element(name) ⇒ void
private
Handle start of an element.
-
#text(value) ⇒ void
(also: #cdata)
private
Handle text content (also aliased as
cdata).
Constructor Details
#initialize(mode) ⇒ Handler
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.
Create a new SAX handler
43 44 45 46 |
# File 'lib/multi_xml/parsers/ox.rb', line 43 def initialize(mode) @mode = mode @stack = [{}] end |
Instance Method Details
#attr(name, value) ⇒ void
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.
This method returns an undefined value.
Handle an attribute
Ignored outside an element (e.g. attributes on the XML declaration
such as <?xml version="1.0"?>, which fire before any start_element).
74 75 76 77 78 79 80 81 |
# File 'lib/multi_xml/parsers/ox.rb', line 74 def attr(name, value) return if @stack.size < 2 name = name.to_s return if xmlns_decl?(name) && @mode != :preserve add_attribute_value(current, format_name(name), value) end |
#end_element(_name) ⇒ void
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.
This method returns an undefined value.
Handle end of an element
96 97 98 99 |
# File 'lib/multi_xml/parsers/ox.rb', line 96 def end_element(_name) strip_whitespace_content if current.key?(TEXT_CONTENT_KEY) @stack.pop end |
#error(message, line, column) ⇒ void
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.
This method returns an undefined value.
Handle parse errors
109 110 111 |
# File 'lib/multi_xml/parsers/ox.rb', line 109 def error(, line, column) raise ::Ox::ParseError, "#{} at #{line}:#{column}" end |
#result ⇒ Hash
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.
Get the parsed result
52 |
# File 'lib/multi_xml/parsers/ox.rb', line 52 def result = @stack.first |
#start_element(name) ⇒ void
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.
This method returns an undefined value.
Handle start of an element
59 60 61 62 63 |
# File 'lib/multi_xml/parsers/ox.rb', line 59 def start_element(name) child = {} add_value(current, format_name(name.to_s), child) @stack << child end |
#text(value) ⇒ void Also known as: cdata
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.
This method returns an undefined value.
Handle text content (also aliased as cdata)
88 |
# File 'lib/multi_xml/parsers/ox.rb', line 88 def text(value) = append_text(current, value) |