mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[xenserver] Use Nokogiri instead of slow REXML for parsing
This commit is contained in:
parent
4e047e9d30
commit
7172c15472
1 changed files with 25 additions and 1 deletions
|
@ -14,7 +14,7 @@ module Fog
|
|||
|
||||
def initialize(host)
|
||||
@factory = XMLRPC::Client.new(host, '/')
|
||||
@factory.set_parser(XMLRPC::XMLParser::REXMLStreamParser.new)
|
||||
@factory.set_parser(NokogiriStreamParser.new)
|
||||
end
|
||||
|
||||
def authenticate( username, password )
|
||||
|
@ -50,6 +50,30 @@ module Fog
|
|||
end
|
||||
end
|
||||
|
||||
class NokogiriStreamParser < XMLRPC::XMLParser::AbstractStreamParser
|
||||
|
||||
def initialize
|
||||
require 'nokogiri/xml/sax/document'
|
||||
require 'nokogiri/xml/sax/parser'
|
||||
|
||||
@parser_class = Class.new(Nokogiri::XML::SAX::Document) do
|
||||
|
||||
include XMLRPC::XMLParser::StreamParserMixin
|
||||
|
||||
alias_method :start_element, :startElement
|
||||
alias_method :end_element, :endElement
|
||||
alias_method :characters, :character
|
||||
alias_method :cdata_block, :character
|
||||
|
||||
def parse(str)
|
||||
Nokogiri::XML::SAX::Parser.new(self).parse(str)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue