Report abuse

XML

1
2
3
4
5
6
7
8
9
  <entry>
    <string>openwire</string>
    <string>tcp://localhost.localdomain:6166</string>
  </entry>
  <entry>
    <string>storeLimit</string>
    <long>1073741824</long>
  </entry>

From JSON

1
2
3
4
5
6
7
8
9
{"map"=>
  [{"entry"=>
      {"long"=>1073741824, "string"=>"storeLimit"},
      {"string"=>["openwire", "tcp://localhost.localdomain:6166"]}]}]} 


Why isnt the 2nd:

{"string"=>"openwire", "string"=> "tcp://localhost.localdomain:6166"}

XML Parser

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
def amqxmldecode(amqmap)
    map = Hash.new

    Document.new(amqmap).root.each_element do |element|
        value = name = nil

        element.each_element_with_text do |e,t|
            name = e.text unless name

            if name
                case e.name
                    when "string"
                        map[name] = e.text

                    when /int|long/
                        map[name] = e.text.to_i

                    when "double"
                        map[name] = e.text.to_f

                    else
                        raise("Unknown data type #{e.name}")
                end
            end
        end
    end

    map
end