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.
1358 1359 1360 |
# File 'lib/moxml/adapter/libxml.rb', line 1358 def initialize(handler) @handler = handler end |
Instance Method Details
#on_cdata_block(content) ⇒ Object
1396 1397 1398 |
# File 'lib/moxml/adapter/libxml.rb', line 1396 def on_cdata_block(content) @handler.on_cdata(content) end |
#on_characters(chars) ⇒ Object
1392 1393 1394 |
# File 'lib/moxml/adapter/libxml.rb', line 1392 def on_characters(chars) @handler.on_characters(chars) end |
#on_comment(msg) ⇒ Object
1400 1401 1402 |
# File 'lib/moxml/adapter/libxml.rb', line 1400 def on_comment(msg) @handler.on_comment(msg) end |
#on_end_document ⇒ Object
1368 1369 1370 |
# File 'lib/moxml/adapter/libxml.rb', line 1368 def on_end_document @handler.on_end_document end |
#on_end_element_ns(name, prefix, _uri) ⇒ Object
1387 1388 1389 1390 |
# File 'lib/moxml/adapter/libxml.rb', line 1387 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
1408 1409 1410 |
# File 'lib/moxml/adapter/libxml.rb', line 1408 def on_error(msg) @handler.on_error(Moxml::ParseError.new(msg)) end |
#on_processing_instruction(target, data) ⇒ Object
1404 1405 1406 |
# File 'lib/moxml/adapter/libxml.rb', line 1404 def on_processing_instruction(target, data) @handler.on_processing_instruction(target, data || "") end |
#on_start_document ⇒ Object
Map LibXML events to Moxml events
1364 1365 1366 |
# File 'lib/moxml/adapter/libxml.rb', line 1364 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).
1378 1379 1380 1381 1382 1383 1384 1385 |
# File 'lib/moxml/adapter/libxml.rb', line 1378 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 |