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.
648 649 650 |
# File 'lib/moxml/adapter/rexml.rb', line 648 def initialize(handler) @handler = handler end |
Instance Method Details
#cdata(content) ⇒ Object
680 681 682 |
# File 'lib/moxml/adapter/rexml.rb', line 680 def cdata(content) @handler.on_cdata(content) end |
#characters(text) ⇒ Object
676 677 678 |
# File 'lib/moxml/adapter/rexml.rb', line 676 def characters(text) @handler.on_characters(text) end |
#comment(text) ⇒ Object
684 685 686 |
# File 'lib/moxml/adapter/rexml.rb', line 684 def comment(text) @handler.on_comment(text) end |
#end_document ⇒ Object
696 697 698 |
# File 'lib/moxml/adapter/rexml.rb', line 696 def end_document @handler.on_end_document end |
#end_element(_uri, _localname, qname) ⇒ Object
672 673 674 |
# File 'lib/moxml/adapter/rexml.rb', line 672 def end_element(_uri, _localname, qname) @handler.on_end_element(qname) end |
#processing_instruction(target, data) ⇒ Object
688 689 690 |
# File 'lib/moxml/adapter/rexml.rb', line 688 def processing_instruction(target, data) @handler.on_processing_instruction(target, data || "") end |
#progress(position) ⇒ Object
705 706 707 |
# File 'lib/moxml/adapter/rexml.rb', line 705 def progress(position) # Progress callback - we don't need to do anything end |
#start_document ⇒ Object
692 693 694 |
# File 'lib/moxml/adapter/rexml.rb', line 692 def start_document @handler.on_start_document end |
#start_element(_uri, _localname, qname, attributes) ⇒ Object
REXML splits element name into uri/localname/qname
653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 |
# File 'lib/moxml/adapter/rexml.rb', line 653 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
701 702 703 |
# File 'lib/moxml/adapter/rexml.rb', line 701 def xmldecl(version, encoding, standalone) # XML declaration - we don't need to do anything end |