File: xmlrpc_adapter.rb

package info (click to toggle)
ruby-ox 2.14.23-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,504 kB
  • sloc: xml: 39,683; ansic: 9,626; ruby: 6,441; sh: 47; makefile: 2
file content (33 lines) | stat: -rw-r--r-- 943 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
require 'ox'

module Ox
  # This is an alternative parser for the stdlib xmlrpc library. It makes
  # use of Ox and is based on REXMLStreamParser. To use it set is as the
  # parser for an XMLRPC client:
  #
  #   require 'xmlrpc/client'
  #   require 'ox/xmlrpc_adapter'
  #   client = XMLRPC::Client.new2('http://some_server/rpc')
  #   client.set_parser(Ox::StreamParser.new)
  class StreamParser < XMLRPC::XMLParser::AbstractStreamParser
    # Create a new instance.
    def initialize
      super
      @parser_class = OxParser
    end

    # The SAX wrapper.
    class OxParser < Ox::Sax
      include XMLRPC::XMLParser::StreamParserMixin

      alias text character
      alias end_element endElement
      alias start_element startElement

      # Initiates the sax parser with the provided string.
      def parse(str)
        Ox.sax_parse(self, StringIO.new(str), symbolize: false, convert_special: true)
      end
    end
  end
end