aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2011-05-27 11:52:43 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2011-05-27 11:52:43 -0700
commit62d5ef0c17b41ce8b3a5578e98081caeb4ba190e (patch)
treecb089c5a50365507519e03a2034c556dd411e316 /activesupport/lib/active_support
parent8628948e2a2c874facc66a1d7b328431f8c0b3c8 (diff)
parent0094351a240598025141409e3aa309ff8b2f5c6c (diff)
downloadrails-62d5ef0c17b41ce8b3a5578e98081caeb4ba190e.tar.gz
rails-62d5ef0c17b41ce8b3a5578e98081caeb4ba190e.tar.bz2
rails-62d5ef0c17b41ce8b3a5578e98081caeb4ba190e.zip
Merge pull request #1346 from arunagw/jdom_file_from_xml_fix
Jdom file from xml fix
Diffstat (limited to 'activesupport/lib/active_support')
-rw-r--r--activesupport/lib/active_support/xml_mini/jdom.rb9
1 files changed, 8 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/xml_mini/jdom.rb b/activesupport/lib/active_support/xml_mini/jdom.rb
index 7aefabfdd1..6c222b83ba 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,6 +134,7 @@ module ActiveSupport
attribute_hash = {}
attributes = element.attributes
for i in 0...attributes.length
+ attribute_hash[CONTENT_KEY] ||= ''
attribute_hash[attributes.item(i).name] = attributes.item(i).value
end
attribute_hash