Skip to content

Commit

Permalink
Adding __content__ into XmlMini_JDOM
Browse files Browse the repository at this point in the history
  • Loading branch information
arunagw committed May 26, 2011
1 parent d341d16 commit d164663
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion activesupport/lib/active_support/xml_mini/jdom.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def parse(data)
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

Expand All @@ -54,9 +54,14 @@ def parse(data)
# 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::
Expand Down Expand Up @@ -84,6 +89,7 @@ def collapse(element)
# 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
Expand Down Expand Up @@ -128,6 +134,7 @@ def get_attributes(element)
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
Expand Down

0 comments on commit d164663

Please sign in to comment.