Class: Moxml::Adapter::Libxml::LibXMLSAXBridge
- Inherits:
-
Object
- Object
- Moxml::Adapter::Libxml::LibXMLSAXBridge
- Includes:
- LibXML::XML::SaxParser::Callbacks, SAX::NamespaceSplitter
- Defined in:
- lib/moxml/adapter/libxml.rb
Overview
Bridge between LibXML SAX and Moxml SAX
Translates LibXML::XML::SaxParser events to Moxml::SAX::Handler events
Constant Summary
Constants included from SAX::NamespaceSplitter
SAX::NamespaceSplitter::EMPTY_NAMESPACES
Instance Method Summary collapse
-
#initialize(handler) ⇒ LibXMLSAXBridge
constructor
A new instance of LibXMLSAXBridge.
- #on_cdata_block(content) ⇒ Object
- #on_characters(chars) ⇒ Object
- #on_comment(msg) ⇒ Object
- #on_end_document ⇒ Object
- #on_end_element_ns(name, prefix, _uri) ⇒ Object
- #on_error(msg) ⇒ Object
- #on_processing_instruction(target, data) ⇒ Object
-
#on_start_document ⇒ Object
Map LibXML events to Moxml events.
-
#on_start_element_ns(name, attributes, prefix, _uri, namespaces) ⇒ Object
libxml strips prefixes and namespace declarations from the plain on_start_element callback; the _ns variants carry them.
Methods included from SAX::NamespaceSplitter
#split_attributes_and_namespaces
Constructor Details
#initialize(handler) ⇒ LibXMLSAXBridge
Returns a new instance of LibXMLSAXBridge.
1326 1327 1328 |
# File 'lib/moxml/adapter/libxml.rb', line 1326 def initialize(handler) @handler = handler end |
Instance Method Details
#on_cdata_block(content) ⇒ Object
1364 1365 1366 |
# File 'lib/moxml/adapter/libxml.rb', line 1364 def on_cdata_block(content) @handler.on_cdata(content) end |
#on_characters(chars) ⇒ Object
1360 1361 1362 |
# File 'lib/moxml/adapter/libxml.rb', line 1360 def on_characters(chars) @handler.on_characters(chars) end |
#on_comment(msg) ⇒ Object
1368 1369 1370 |
# File 'lib/moxml/adapter/libxml.rb', line 1368 def on_comment(msg) @handler.on_comment(msg) end |
#on_end_document ⇒ Object
1336 1337 1338 |
# File 'lib/moxml/adapter/libxml.rb', line 1336 def on_end_document @handler.on_end_document end |
#on_end_element_ns(name, prefix, _uri) ⇒ Object
1355 1356 1357 1358 |
# File 'lib/moxml/adapter/libxml.rb', line 1355 def on_end_element_ns(name, prefix, _uri) qualified = prefix ? "#{prefix}:#{name}" : name.to_s @handler.on_end_element(qualified) end |
#on_error(msg) ⇒ Object
1376 1377 1378 |
# File 'lib/moxml/adapter/libxml.rb', line 1376 def on_error(msg) @handler.on_error(Moxml::ParseError.new(msg)) end |
#on_processing_instruction(target, data) ⇒ Object
1372 1373 1374 |
# File 'lib/moxml/adapter/libxml.rb', line 1372 def on_processing_instruction(target, data) @handler.on_processing_instruction(target, data || "") end |
#on_start_document ⇒ Object
Map LibXML events to Moxml events
1332 1333 1334 |
# File 'lib/moxml/adapter/libxml.rb', line 1332 def on_start_document @handler.on_start_document end |
#on_start_element_ns(name, attributes, prefix, _uri, namespaces) ⇒ Object
libxml strips prefixes and namespace declarations from the plain on_start_element callback; the _ns variants carry them. The namespaces hash uses nil for the default declaration — the same key convention as every other bridge's split. Attribute name prefixes are lost by the binding in both callbacks (documented limitation).
1346 1347 1348 1349 1350 1351 1352 1353 |
# File 'lib/moxml/adapter/libxml.rb', line 1346 def on_start_element_ns(name, attributes, prefix, _uri, namespaces) normalized = (attributes || {}).map { |k, v| [k.to_s, v] } attr_hash, = split_attributes_and_namespaces(normalized) do |v| Moxml::Adapter::Base.decode_entities(v) end qualified = prefix ? "#{prefix}:#{name}" : name.to_s @handler.on_start_element(qualified, attr_hash, namespaces || {}) end |