Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ gemspec
group :development do
gem "bundler"
gem "libxml-ruby", platforms: [:ruby, :jruby]
gem "nokogiri", platforms: [:ruby, :jruby]
gem "rake"
gem "test-unit"
end
5 changes: 4 additions & 1 deletion lib/xmlrpc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,12 @@
# * libxml (LibXMLStreamParser)
# * Compiled
# * See https://rubygems.org/gems/libxml-ruby/
# * nokogiri (NokogiriStreamParser)
# * Compiled
# * See https://nokogiri.org
#
# * General
# * possible to choose between XMLParser module (Expat wrapper) and REXML (pure Ruby) parsers
# * possible to choose between REXML (pure Ruby) and LibXML/Nokogiri (compiled) parsers
# * Marshalling Ruby objects to Hashes and reconstruct them later from a Hash
# * SandStorm component architecture XMLRPC::Client interface
#
Expand Down
1 change: 1 addition & 0 deletions lib/xmlrpc/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module Config
#
# * XMLParser::REXMLStreamParser
# * XMLParser::LibXMLStreamParser
# * XMLParser::NokogiriStreamParser
DEFAULT_PARSER = XMLParser::REXMLStreamParser

# enable <code><nil/></code> tag
Expand Down
46 changes: 45 additions & 1 deletion lib/xmlrpc/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,51 @@ def parse(str)
end
end

Classes = [REXMLStreamParser, LibXMLStreamParser]
class NokogiriStreamParser < AbstractStreamParser
def initialize
require 'nokogiri'
@parser_class = NokogiriStreamListener
end

class NokogiriStreamListener
include StreamParserMixin

def self.handler
# We need to construct this on first use, since we cannot be sure Nokogiri is available
@handler ||= begin
Class.new(Nokogiri::XML::SAX::Document) do
def initialize(parent)
super()
@parent = parent
end

def start_element_namespace(name, attrs = [], prefix = nil, uri = nil, ns = [])
@parent.startElement(name, attrs)
end

def end_element_namespace(name, prefix = nil, uri = nil)
@parent.endElement(name)
end

def characters(string)
@parent.character(string)
end

def cdata_block(string)
@parent.character(string)
end
end
end
end

def parse(str)
parser = Nokogiri::XML::SAX::Parser.new(self.class.handler.new(self))
parser.parse(str)
end
end
end

Classes = [REXMLStreamParser, LibXMLStreamParser, NokogiriStreamParser]

# yields an instance of each installed parser
def self.each_installed_parser
Expand Down
Loading