Permalink
Browse files

Merge pull request #86 from jfontan/xmlrpc_adapter

Added parser for stdlib xmlrpc library
  • Loading branch information...
2 parents 8a9f0d2 + 47bb395 commit f859c20bdeba87b3ac6e23a60a38e059e1e03494 @ohler55 committed Jan 15, 2014
Showing with 32 additions and 0 deletions.
  1. +32 −0 lib/ox/xmlrpc_adapter.rb
View
@@ -0,0 +1,32 @@
+
+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
+ def initialize
+ @parser_class = OxParser
+ end
+
+ class OxParser < Ox::Sax
+ include XMLRPC::XMLParser::StreamParserMixin
+
+ alias :text :character
+ alias :end_element :endElement
+ alias :start_element :startElement
+
+ def parse(str)
+ Ox.sax_parse(self, StringIO.new(str), :symbolize => false)
+ end
+ end
+ end
+end

0 comments on commit f859c20

Please sign in to comment.