Class: Moxml::Adapter::REXMLSAX2Bridge

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(handler) ⇒ REXMLSAX2Bridge

Returns a new instance of REXMLSAX2Bridge.



542
543
544
# File 'lib/moxml/adapter/rexml.rb', line 542

def initialize(handler)
  @handler = handler
end

Instance Method Details

#cdata(content) ⇒ Object



574
575
576
# File 'lib/moxml/adapter/rexml.rb', line 574

def cdata(content)
  @handler.on_cdata(content)
end

#characters(text) ⇒ Object



570
571
572
# File 'lib/moxml/adapter/rexml.rb', line 570

def characters(text)
  @handler.on_characters(text)
end

#comment(text) ⇒ Object



578
579
580
# File 'lib/moxml/adapter/rexml.rb', line 578

def comment(text)
  @handler.on_comment(text)
end

#end_documentObject



590
591
592
# File 'lib/moxml/adapter/rexml.rb', line 590

def end_document
  @handler.on_end_document
end

#end_element(_uri, _localname, qname) ⇒ Object



566
567
568
# File 'lib/moxml/adapter/rexml.rb', line 566

def end_element(_uri, _localname, qname)
  @handler.on_end_element(qname)
end

#processing_instruction(target, data) ⇒ Object



582
583
584
# File 'lib/moxml/adapter/rexml.rb', line 582

def processing_instruction(target, data)
  @handler.on_processing_instruction(target, data || "")
end

#progress(position) ⇒ Object



599
600
601
# File 'lib/moxml/adapter/rexml.rb', line 599

def progress(position)
  # Progress callback - we don't need to do anything
end

#start_documentObject



586
587
588
# File 'lib/moxml/adapter/rexml.rb', line 586

def start_document
  @handler.on_start_document
end

#start_element(_uri, _localname, qname, attributes) ⇒ Object

REXML splits element name into uri/localname/qname



547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
# File 'lib/moxml/adapter/rexml.rb', line 547

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



595
596
597
# File 'lib/moxml/adapter/rexml.rb', line 595

def xmldecl(version, encoding, standalone)
  # XML declaration - we don't need to do anything
end