I'm trying to parse XML in Ruby using Nori, which internally uses Nokogiri. The XML has some tags repeated and the library parses repeated tags as Arrays and non-repeated tags as normal elements (Hash)
<nodes>
<foo>
<name>a</name>
</foo>
<bar>
<name>b</name>
</bar>
<baz>
<name>c</name>
</baz>
<foo>
<name>d</name>
</foo>
<bar>
<name>e</name>
</bar>
</nodes>
is parsed as
{nodes: {
foo: [{name: "a"}, {name: "d"}],
bar: [{name: "b"}, {name: "e"}],
baz: {name: "c"}
}}
How do i retain the order of elements in the resulting hash like the output below?
{nodes: [
{foo: {name: "a"}},
{bar: {name: "b"}},
{baz: {name: "c"}},
{foo: {name: "d"}},
{bar: {name: "e"}},
]}
(This may be a library specific question. But the intention is to know if anyone has faced a similar issue and how to parse it correctly)