Class: MultiXML::Parsers::NokogiriSax::Handler Private

Inherits:
Nokogiri::XML::SAX::Document
  • Object
show all
Includes:
SaxHandler
Defined in:
lib/multi_xml/parsers/nokogiri_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.

Nokogiri SAX handler.

Nokogiri always invokes start_element_namespace (even for documents without namespaces — prefix/uri come through as nil). We don't define start_element because it would never fire.

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



50
51
52
53
# File 'lib/multi_xml/parsers/nokogiri_sax.rb', line 50

def initialize(mode)
  super()
  initialize_handler(mode)
end

Instance Method Details

#characters(text) ⇒ void Also known as: cdata_block

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 character data

Parameters:

  • text (String)

    Text content



114
# File 'lib/multi_xml/parsers/nokogiri_sax.rb', line 114

def characters(text) = append_text(text)

#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)



66
67
# File 'lib/multi_xml/parsers/nokogiri_sax.rb', line 66

def end_document
end

#end_element_namespace(_local, _prefix = nil, _uri = nil) ⇒ 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 a namespaced element

Parameters:

  • _local (String)

    Local element name (unused)

  • _prefix (String, nil) (defaults to: nil)

    Namespace prefix (unused)

  • _uri (String, nil) (defaults to: nil)

    Namespace URI (unused)



105
106
107
# File 'lib/multi_xml/parsers/nokogiri_sax.rb', line 105

def end_element_namespace(_local, _prefix = nil, _uri = nil)
  handle_end_element
end

#error(message) ⇒ 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

Raises:

  • (Nokogiri::XML::SyntaxError)

    always



75
76
77
# File 'lib/multi_xml/parsers/nokogiri_sax.rb', line 75

def error(message)
  raise ::Nokogiri::XML::SyntaxError, message
end

#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)



59
60
# File 'lib/multi_xml/parsers/nokogiri_sax.rb', line 59

def start_document
end

#start_element_namespace(local, attrs = [], prefix = nil, _uri = nil, ns = []) ⇒ 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 a namespaced element

Signature is fixed by the Nokogiri SAX protocol.

rubocop:disable Metrics/ParameterLists, Naming/MethodParameterName

Parameters:

  • local (String)

    Local element name

  • attrs (Array<Nokogiri::XML::SAX::Parser::Attribute>) (defaults to: [])

    Attributes

  • prefix (String, nil) (defaults to: nil)

    Element namespace prefix

  • _uri (String, nil) (defaults to: nil)

    Element namespace URI (unused)

  • ns (Array) (defaults to: [])

    Namespace declarations as [prefix, uri] pairs



91
92
93
94
95
# File 'lib/multi_xml/parsers/nokogiri_sax.rb', line 91

def start_element_namespace(local, attrs = [], prefix = nil, _uri = nil, ns = [])
  ns_decls = ns.map { |p, u| [normalize(p), u] }
  attr_tuples = attrs.map { |a| [normalize(a.prefix), a.localname, a.value] }
  handle_start_element_ns(local, normalize(prefix), attr_tuples, ns_decls)
end