From 88813e1cf75ea7e1ca895c61b4682ca05161fae0 Mon Sep 17 00:00:00 2001 From: Arun Agrawal Date: Wed, 1 Jun 2011 14:41:37 +0530 Subject: [PATCH] Fixing XMLMini_JDOM --- activesupport/lib/active_support/xml_mini/jdom.rb | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/activesupport/lib/active_support/xml_mini/jdom.rb b/activesupport/lib/active_support/xml_mini/jdom.rb index 7aefabfdd1..0dee0f3a07 100644 --- a/activesupport/lib/active_support/xml_mini/jdom.rb +++ b/activesupport/lib/active_support/xml_mini/jdom.rb @@ -41,7 +41,7 @@ module ActiveSupport 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) + merge_element!({CONTENT_KEY => ''}, doc.document_element) end end @@ -54,9 +54,14 @@ module ActiveSupport # element:: # XML element to merge into hash def merge_element!(hash, element) + delete_empty(hash) merge!(hash, element.tag_name, collapse(element)) end + def delete_empty(hash) + hash.delete(CONTENT_KEY) if hash[CONTENT_KEY] == '' + end + # Actually converts an XML document element into a data structure. # # element:: @@ -84,6 +89,7 @@ module ActiveSupport # element:: # XML element whose texts are to me merged into the hash def merge_texts!(hash, element) + delete_empty(hash) text_children = texts(element) if text_children.join.empty? hash @@ -128,8 +134,9 @@ module ActiveSupport attribute_hash = {} attributes = element.attributes for i in 0...attributes.length - attribute_hash[attributes.item(i).name] = attributes.item(i).value - end + attribute_hash[CONTENT_KEY] ||= '' + attribute_hash[attributes.item(i).name] = attributes.item(i).value + end attribute_hash end