How to convert XML file into NodeJS array while keeping the same order as the original file?

50 Views Asked by At

I am trying to convert XML file into NodeJS object while keeping the same order as the original file. I have tried using the library xml2js, but it produces an object (not an array), and merges the tags with the same name.

For example the following XML :

<xml>
<a>...</a>
<b>...</b>
<a>...</a>
<c>...</c>
</xml>

results, with xml2js, in something like :

{
a : [[Object], [Object]],
b : [[Object]],
c : [[Object]],
}

'a' tags are merged, which I don't want.

What I want is something like :

[
{a : [Object]},
{b : [Object]},
{a : [Object]},
{c : [Object]}
]

thus keeping the same order as the original XML file. Do you have any idea how to achieve this ? Thanks ?

0

There are 0 best solutions below