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/jdom.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/jdom.rb')
-rw-r--r-- | activesupport/lib/active_support/xml_mini/jdom.rb | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/activesupport/lib/active_support/xml_mini/jdom.rb b/activesupport/lib/active_support/xml_mini/jdom.rb index d795d55690..1cd714d864 100644 --- a/activesupport/lib/active_support/xml_mini/jdom.rb +++ b/activesupport/lib/active_support/xml_mini/jdom.rb @@ -24,15 +24,19 @@ module ActiveSupport node_type_map = {} NODE_TYPE_NAMES.each { |type| node_type_map[Node.send(type)] = type } - # Parse an XML Document string into a simple hash using Java's jdom. - # string:: - # XML Document string to parse - def parse(string) - if string.blank? + # Parse an XML Document string or IO into a simple hash using Java's jdom. + # data:: + # XML Document string or IO to parse + def parse(data) + if data.respond_to?(:read) + data = data.read + end + + if data.blank? {} else @dbf = DocumentBuilderFactory.new_instance - xml_string_reader = StringReader.new(string) + xml_string_reader = StringReader.new(data) xml_input_source = InputSource.new(xml_string_reader) doc = @dbf.new_document_builder.parse(xml_input_source) merge_element!({}, doc.document_element) |