35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/base/parsers/rexml.rb', line 35
def self.parse_rexml_node(node)
attributes = {}
children = {}
text = ''
node.attributes.each do |name, value|
attributes["@#{name}"] = value
end
node.each_element do |child|
if child.has_elements? || child.has_text?
response = parse_rexml_node(child)
unless children["#{child.name}"]
children["#{child.name}"] = response
else
children["#{child.name}"] = [ children["#{child.name}"] ] unless children["#{child.name}"].is_a?(Array)
children["#{child.name}"] << response
end
else
children["#{child.name}"] = nil
end
end
text << node.texts.join('')
if attributes._blank? && children._blank?
result = text._blank? ? nil : text
else
result = attributes.merge(children)
result.merge!("@@text" => text) unless text._blank?
end
result = { node.name => result } if node.parent.is_a?(REXML::Document)
result
end
|