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.



529
530
531
# File 'lib/moxml/adapter/rexml.rb', line 529

def initialize(handler)
  @handler = handler
end

Instance Method Details

#cdata(content) ⇒ Object



561
562
563
# File 'lib/moxml/adapter/rexml.rb', line 561

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

#characters(text) ⇒ Object



557
558
559
# File 'lib/moxml/adapter/rexml.rb', line 557

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

#comment(text) ⇒ Object



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

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

#end_documentObject



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

def end_document
  @handler.on_end_document
end

#end_element(_uri, _localname, qname) ⇒ Object



553
554
555
# File 'lib/moxml/adapter/rexml.rb', line 553

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

#processing_instruction(target, data) ⇒ Object



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

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

#progress(position) ⇒ Object



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

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

#start_documentObject



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

def start_document
  @handler.on_start_document
end

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

REXML splits element name into uri/localname/qname



534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
# File 'lib/moxml/adapter/rexml.rb', line 534

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



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

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