Class: MultiXML::Parsers::LibxmlSax::Handler Private

Inherits:
Object
  • Object
show all
Includes:
LibXML::XML::SaxParser::Callbacks, SaxHandler
Defined in:
lib/multi_xml/parsers/libxml_sax.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.

LibXML SAX handler.

libxml-ruby's namespace-aware callback strips prefixes from the attrs hash, so we rely on the qname-preserving on_start_element callback and resolve namespaces via SaxHandler's scope stack.

Instance Attribute Summary

Attributes included from SaxHandler

#result

Instance Method Summary collapse

Methods included from SaxHandler

#initialize_handler

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

Parameters:

  • mode (Symbol)

    Namespace handling mode



110
111
112
# File 'lib/multi_xml/parsers/libxml_sax.rb', line 110

def initialize(mode)
  initialize_handler(mode)
end

Instance Method Details

#on_end_documentvoid

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 document (no-op)



125
126
# File 'lib/multi_xml/parsers/libxml_sax.rb', line 125

def on_end_document
end

#on_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 (String)

    Element name (unused)



162
163
164
# File 'lib/multi_xml/parsers/libxml_sax.rb', line 162

def on_end_element(_name)
  handle_end_element
end

#on_error(_error) ⇒ 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 (no-op; libxml-ruby raises directly)

Parameters:

  • _error (String)

    Error message (unused)



133
134
# File 'lib/multi_xml/parsers/libxml_sax.rb', line 133

def on_error(_error)
end

#on_start_documentvoid

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 document (no-op)



118
119
# File 'lib/multi_xml/parsers/libxml_sax.rb', line 118

def on_start_document
end

#on_start_element(name, attrs = {}) ⇒ 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

libxml-ruby strips xmlns declarations from attrs and passes through prefixed names for regular attributes. Since libxml_sax only uses this handler in :strip mode, we route through the namespace-aware entrypoint with empty ns_decls and treat attribute qnames as-if they had no namespace — matching the desired :strip output.

Parameters:

  • name (String)

    Element name (possibly prefixed)

  • attrs (Hash) (defaults to: {})

    Attributes as name => value



148
149
150
151
152
153
154
155
# File 'lib/multi_xml/parsers/libxml_sax.rb', line 148

def on_start_element(name, attrs = {})
  prefix, local = sax_split_qname(name.to_s)
  tuples = attrs.map do |k, v|
    ap, al = sax_split_qname(k.to_s)
    [ap, al, v]
  end
  handle_start_element_ns(local, prefix, tuples, [])
end