Sha256: 080e5fd7d375c10c8d817047f46a03a2e4cabc7f9b688b941c2a2c404cd78965

Contents?: true

Size: 774 Bytes

Versions: 2

Compression:

Stored size: 774 Bytes

Contents

require 'sax-machine/handlers/sax_abstract_handler'
require 'oga'

module SAXMachine
  class SAXOgaHandler
    include SAXAbstractHandler

    def initialize(*args)
      _initialize(*args)
    end

    def sax_parse(xml_input)
      Oga.sax_parse_xml(self, xml_input)
    end

    def on_element(namespace, name, attrs)
      _start_element(node_name(namespace, name), attrs.map { |a| [a.name, a.value] })
    end

    def after_element(namespace, name)
      _end_element(node_name(namespace, name))
    end

    def on_error(*args)
      _error(args.join(" "))
    end

    alias_method :on_text, :_characters
    alias_method :on_cdata, :_characters

    private

    def node_name(namespace, name)
      namespace ? [namespace, name].join(":") : name
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sax-machine-1.3.1 lib/sax-machine/handlers/sax_oga_handler.rb
sax-machine-1.3.0 lib/sax-machine/handlers/sax_oga_handler.rb