Permalink
Browse files

enable *real* IO parsing for the libxml, nokogiri and rexml backends [#…

…2659 state:resolved]

Signed-off-by: Joshua Peek <josh@joshpeek.com>
  • Loading branch information...
1 parent a94e7d7 commit 69bc2043f93890048e415dd7c5f1feba5a20d145 @brianmario brianmario committed with josh Jun 9, 2009
@@ -9,16 +9,18 @@ module XmlMini_LibXML #:nodoc:
# data::
# XML Document string or IO to parse
def parse(data)
- if data.respond_to?(:read)
- data = data.read
+ if !data.respond_to?(:read)
+ data = StringIO.new(data || '')
end
-
+
LibXML::XML.default_keep_blanks = false
-
- if data.blank?
+
+ char = data.getc
+ if char.nil?
{}
else
- LibXML::XML::Parser.string(data.strip).parse.to_hash
+ data.ungetc(char)
+ LibXML::XML::Parser.io(data).parse.to_hash
end
end
@@ -9,13 +9,15 @@ module XmlMini_Nokogiri #:nodoc:
# data::
# XML Document string or IO to parse
def parse(data)
- if data.respond_to?(:read)
- data = data.read
+ if !data.respond_to?(:read)
+ data = StringIO.new(data || '')
end
-
- if data.blank?
+
+ char = data.getc
+ if char.nil?
{}
else
+ data.ungetc(char)
doc = Nokogiri::XML(data)
raise doc.errors.first if doc.errors.length > 0
doc.to_hash
@@ -15,13 +15,19 @@ module XmlMini_REXML #:nodoc:
# data::
# XML Document string or IO to parse
def parse(data)
- if data.respond_to?(:read)
- data = data.read
+ if !data.respond_to?(:read)
+ data = StringIO.new(data || '')
+ end
+
+ char = data.getc
+ if char.nil?
+ {}
+ else
+ data.ungetc(char)
+ require 'rexml/document' unless defined?(REXML::Document)
+ doc = REXML::Document.new(data)
+ merge_element!({}, doc.root)
end
-
- require 'rexml/document' unless defined?(REXML::Document)
- doc = REXML::Document.new(data)
- merge_element!({}, doc.root)
end
private

0 comments on commit 69bc204

Please sign in to comment.