diff options
author | Brian Lopez <seniorlopez@gmail.com> | 2009-05-17 10:37:30 -0500 |
---|---|---|
committer | Joshua Peek <josh@joshpeek.com> | 2009-05-17 10:37:52 -0500 |
commit | 53dda29f8b34073a4b135ee224c1d09c1f10de02 (patch) | |
tree | 4046b55b7609e20c6ef4cc8732724b774b997bf8 /activesupport/lib/active_support/xml_mini/rexml.rb | |
parent | 344ee681d6a89ea1da71c39e75c29e0cbda44914 (diff) | |
download | rails-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/rexml.rb')
-rw-r--r-- | activesupport/lib/active_support/xml_mini/rexml.rb | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/activesupport/lib/active_support/xml_mini/rexml.rb b/activesupport/lib/active_support/xml_mini/rexml.rb index 5033210aae..1184d2d6c9 100644 --- a/activesupport/lib/active_support/xml_mini/rexml.rb +++ b/activesupport/lib/active_support/xml_mini/rexml.rb @@ -7,16 +7,20 @@ module ActiveSupport CONTENT_KEY = '__content__'.freeze - # Parse an XML Document string into a simple hash + # Parse an XML Document string or IO into a simple hash # # Same as XmlSimple::xml_in but doesn't shoot itself in the foot, # and uses the defaults from ActiveSupport # - # string:: - # XML Document string to parse - def parse(string) + # data:: + # XML Document string or IO to parse + def parse(data) + if data.respond_to?(:read) + data = data.read + end + require 'rexml/document' unless defined?(REXML::Document) - doc = REXML::Document.new(string) + doc = REXML::Document.new(data) merge_element!({}, doc.root) end |