Sha256: 4952aaf08a2aa338b7b836fc9db59e1f96165722187699a73d62155d50fd150f

Contents?: true

Size: 1.66 KB

Versions: 8

Compression:

Stored size: 1.66 KB

Contents

require 'nokogiri'

module XSD # :nodoc:
  module XMLParser # :nodoc:
    ###
    # Nokogiri XML parser for soap4r.
    #
    # Nokogiri may be used as the XML parser in soap4r.  Simply require
    # 'xsd/xmlparser/nokogiri' in your soap4r applications, and soap4r
    # will use Nokogiri as it's XML parser.  No other changes should be
    # required to use Nokogiri as the XML parser.
    #
    # Example (using UW ITS Web Services):
    #
    #   require 'rubygems'
    #   gem 'soap4r'
    #   require 'nokogiri'
    #   require 'xsd/xmlparser/nokogiri'
    #   require 'defaultDriver'
    #
    #   obj = AvlPortType.new
    #   obj.getLatestByRoute(obj.getAgencies, 8).each do |event|
    #     ...
    #   end
    class Nokogiri < XSD::XMLParser::Parser
      ###
      # Create a new XSD parser with +host+ and +opt+
      def initialize host, opt = {}
        super
        @parser = ::Nokogiri::XML::SAX::Parser.new(self, @charset || 'UTF-8')
      end

      ###
      # Start parsing +string_or_readable+
      def do_parse string_or_readable
        @parser.parse(string_or_readable)
      end

      ###
      # Handle the start_element event with +name+ and +attrs+
      def start_element name, attrs = []
        super(name, Hash[*attrs])
      end

      ###
      # Handle errors with message +msg+
      def error msg
        raise ParseError.new(msg)
      end
      alias :warning :error

      ###
      # Handle cdata_blocks containing +string+
      def cdata_block string
        characters string
      end

      %w{ start_document end_document comment }.each do |name|
        class_eval %{ def #{name}(*args); end }
      end
      add_factory(self)
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
nokogiri-1.3.0-x86-mingw32 lib/xsd/xmlparser/nokogiri.rb
nokogiri-1.3.0-java lib/xsd/xmlparser/nokogiri.rb
nokogiri-1.3.1-x86-mingw32 lib/xsd/xmlparser/nokogiri.rb
nokogiri-1.3.1-java lib/xsd/xmlparser/nokogiri.rb
nokogiri-1.3.0 lib/xsd/xmlparser/nokogiri.rb
nokogiri-1.3.0-x86-mswin32 lib/xsd/xmlparser/nokogiri.rb
nokogiri-1.3.1-x86-mswin32 lib/xsd/xmlparser/nokogiri.rb
nokogiri-1.3.1 lib/xsd/xmlparser/nokogiri.rb