aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/xml_mini/libxml.rb
diff options
context:
space:
mode:
authorBrian Lopez <seniorlopez@gmail.com>2009-05-17 10:37:30 -0500
committerJoshua Peek <josh@joshpeek.com>2009-05-17 10:37:52 -0500
commit53dda29f8b34073a4b135ee224c1d09c1f10de02 (patch)
tree4046b55b7609e20c6ef4cc8732724b774b997bf8 /activesupport/lib/active_support/xml_mini/libxml.rb
parent344ee681d6a89ea1da71c39e75c29e0cbda44914 (diff)
downloadrails-53dda29f8b34073a4b135ee224c1d09c1f10de02.tar.gz
rails-53dda29f8b34073a4b135ee224c1d09c1f10de02.tar.bz2
rails-53dda29f8b34073a4b135ee224c1d09c1f10de02.zip
Add support for parsing XML and JSON from an IO as well as a string [#2659 state:resolved]
Signed-off-by: Joshua Peek <josh@joshpeek.com>
Diffstat (limited to 'activesupport/lib/active_support/xml_mini/libxml.rb')
-rw-r--r--activesupport/lib/active_support/xml_mini/libxml.rb16
1 files changed, 10 insertions, 6 deletions
diff --git a/activesupport/lib/active_support/xml_mini/libxml.rb b/activesupport/lib/active_support/xml_mini/libxml.rb
index 370205409a..d4c4dc7be5 100644
--- a/activesupport/lib/active_support/xml_mini/libxml.rb
+++ b/activesupport/lib/active_support/xml_mini/libxml.rb
@@ -5,16 +5,20 @@ module ActiveSupport
module XmlMini_LibXML #:nodoc:
extend self
- # Parse an XML Document string into a simple hash using libxml.
- # string::
- # XML Document string to parse
- def parse(string)
+ # Parse an XML Document string or IO into a simple hash using libxml.
+ # data::
+ # XML Document string or IO to parse
+ def parse(data)
+ if data.respond_to?(:read)
+ data = data.read
+ end
+
LibXML::XML.default_keep_blanks = false
- if string.blank?
+ if data.blank?
{}
else
- LibXML::XML::Parser.string(string.strip).parse.to_hash
+ LibXML::XML::Parser.string(data.strip).parse.to_hash
end
end