Class: Moxml::Adapter::REXMLSAX2Bridge
- Inherits:
-
Object
- Object
- Moxml::Adapter::REXMLSAX2Bridge
- Defined in:
- lib/moxml/adapter/rexml.rb
Overview
Bridge between REXML SAX2 and Moxml SAX
Translates REXML::SAX2Parser events to Moxml::SAX::Handler events
Instance Method Summary collapse
- #cdata(content) ⇒ Object
- #characters(text) ⇒ Object
- #comment(text) ⇒ Object
- #end_document ⇒ Object
- #end_element(_uri, _localname, qname) ⇒ Object
-
#initialize(handler) ⇒ REXMLSAX2Bridge
constructor
A new instance of REXMLSAX2Bridge.
- #processing_instruction(target, data) ⇒ Object
- #progress(position) ⇒ Object
- #start_document ⇒ Object
-
#start_element(_uri, _localname, qname, attributes) ⇒ Object
REXML splits element name into uri/localname/qname.
-
#xmldecl(version, encoding, standalone) ⇒ Object
REXML calls these but we don’t need to handle them.
Constructor Details
#initialize(handler) ⇒ REXMLSAX2Bridge
Returns a new instance of REXMLSAX2Bridge.
576 577 578 |
# File 'lib/moxml/adapter/rexml.rb', line 576 def initialize(handler) @handler = handler end |
Instance Method Details
#cdata(content) ⇒ Object
608 609 610 |
# File 'lib/moxml/adapter/rexml.rb', line 608 def cdata(content) @handler.on_cdata(content) end |
#characters(text) ⇒ Object
604 605 606 |
# File 'lib/moxml/adapter/rexml.rb', line 604 def characters(text) @handler.on_characters(text) end |
#comment(text) ⇒ Object
612 613 614 |
# File 'lib/moxml/adapter/rexml.rb', line 612 def comment(text) @handler.on_comment(text) end |
#end_document ⇒ Object
624 625 626 |
# File 'lib/moxml/adapter/rexml.rb', line 624 def end_document @handler.on_end_document end |
#end_element(_uri, _localname, qname) ⇒ Object
600 601 602 |
# File 'lib/moxml/adapter/rexml.rb', line 600 def end_element(_uri, _localname, qname) @handler.on_end_element(qname) end |
#processing_instruction(target, data) ⇒ Object
616 617 618 |
# File 'lib/moxml/adapter/rexml.rb', line 616 def processing_instruction(target, data) @handler.on_processing_instruction(target, data || "") end |
#progress(position) ⇒ Object
633 634 635 |
# File 'lib/moxml/adapter/rexml.rb', line 633 def progress(position) # Progress callback - we don't need to do anything end |
#start_document ⇒ Object
620 621 622 |
# File 'lib/moxml/adapter/rexml.rb', line 620 def start_document @handler.on_start_document end |
#start_element(_uri, _localname, qname, attributes) ⇒ Object
REXML splits element name into uri/localname/qname
581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 |
# File 'lib/moxml/adapter/rexml.rb', line 581 def start_element(_uri, _localname, qname, attributes) # Convert REXML attributes to hash attr_hash = {} ns_hash = {} attributes.each do |name, value| if name.to_s.start_with?("xmlns") # Namespace declaration prefix = name.to_s == "xmlns" ? nil : name.to_s.sub("xmlns:", "") ns_hash[prefix] = value else attr_hash[name.to_s] = value end end # Use qname (qualified name) for element name @handler.on_start_element(qname, attr_hash, ns_hash) end |
#xmldecl(version, encoding, standalone) ⇒ Object
REXML calls these but we don’t need to handle them
629 630 631 |
# File 'lib/moxml/adapter/rexml.rb', line 629 def xmldecl(version, encoding, standalone) # XML declaration - we don't need to do anything end |