Class: Canon::Xml::Sax::MoxmlDriver

Inherits:
Moxml::SAX::Handler
  • Object
show all
Defined in:
lib/canon/xml/sax/moxml_driver.rb

Overview

moxml SAX driver (rexml adapter under Opal). moxml splits namespace declarations out of the attribute hash and reports them separately, so this driver recombines them as inline "xmlns"/"xmlns:prefix" pairs to match the builder's engine-neutral protocol.

Instance Method Summary collapse

Constructor Details

#initialize(builder) ⇒ MoxmlDriver

Returns a new instance of MoxmlDriver.



11
12
13
14
# File 'lib/canon/xml/sax/moxml_driver.rb', line 11

def initialize(builder)
  super()
  @builder = builder
end

Instance Method Details

#on_cdata(text) ⇒ Object



40
41
42
# File 'lib/canon/xml/sax/moxml_driver.rb', line 40

def on_cdata(text)
  @builder.cdata(text)
end

#on_characters(text) ⇒ Object



36
37
38
# File 'lib/canon/xml/sax/moxml_driver.rb', line 36

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

#on_comment(text) ⇒ Object



44
45
46
# File 'lib/canon/xml/sax/moxml_driver.rb', line 44

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

#on_end_element(name) ⇒ Object



32
33
34
# File 'lib/canon/xml/sax/moxml_driver.rb', line 32

def on_end_element(name)
  @builder.end_element(name)
end

#on_error(error) ⇒ Object



52
53
54
# File 'lib/canon/xml/sax/moxml_driver.rb', line 52

def on_error(error)
  @builder.error(error.message.to_s)
end

#on_processing_instruction(name, content) ⇒ Object



48
49
50
# File 'lib/canon/xml/sax/moxml_driver.rb', line 48

def on_processing_instruction(name, content)
  @builder.processing_instruction(name, content || "")
end

#on_start_element(name, attributes = {}, namespaces = {}) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/canon/xml/sax/moxml_driver.rb', line 20

def on_start_element(name, attributes = {}, namespaces = {})
  attrs = attributes.to_a
  namespaces.each do |prefix, uri|
    attrs << if prefix.nil? || prefix.empty?
               ["xmlns", uri]
             else
               ["xmlns:#{prefix}", uri]
             end
  end
  @builder.start_element(name, attrs)
end

#parse(xml_string) ⇒ Object



16
17
18
# File 'lib/canon/xml/sax/moxml_driver.rb', line 16

def parse(xml_string)
  Canon::XmlParsing.moxml_context.sax_parse(xml_string, self)
end