Class: MultiXml::Parsers::Ox::Handler Private

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializeHandler

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



35
36
37
# File 'lib/multi_xml/parsers/ox.rb', line 35

def initialize
  @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

Parameters:

  • name (Symbol)

    Attribute name

  • value (String)

    Attribute value



69
70
71
# File 'lib/multi_xml/parsers/ox.rb', line 69

def attr(name, value)
  add_value(name.to_s, value) unless @stack.empty?
end

#cdata(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 CDATA content

Parameters:

  • value (String)

    CDATA content



83
# File 'lib/multi_xml/parsers/ox.rb', line 83

def cdata(value) = add_value(TEXT_CONTENT_KEY, value)

#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

Parameters:

  • _name (Symbol)

    Element name (unused)



59
60
61
62
# File 'lib/multi_xml/parsers/ox.rb', line 59

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

Parameters:

  • message (String)

    Error message

  • line (Integer)

    Line number

  • column (Integer)

    Column number

Raises:

  • (Ox::ParseError)

    always



92
93
94
# File 'lib/multi_xml/parsers/ox.rb', line 92

def error(message, line, column)
  raise ::Ox::ParseError, "#{message} at #{line}:#{column}"
end

#resultHash?

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

Returns:

  • (Hash, nil)

    the root hash or nil if empty



42
# File 'lib/multi_xml/parsers/ox.rb', line 42

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

Parameters:

  • name (Symbol)

    Element name



48
49
50
51
52
53
# File 'lib/multi_xml/parsers/ox.rb', line 48

def start_element(name)
  @stack << {} if @stack.empty?
  child = {}
  add_value(name.to_s, child)
  @stack << child
end

#text(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 text content

Parameters:

  • value (String)

    Text content



77
# File 'lib/multi_xml/parsers/ox.rb', line 77

def text(value) = add_value(TEXT_CONTENT_KEY, value)