I have an XML file which looks like this:
<Item prop="foo">
<A key="1">
<B key="2">
<A key="3">
<C key="4">
<A key="5">
<A key="6">
</Item>
<Item .../>
<Item .../>
I want to parse this file into an array of Item
s, looking like the following:
[
{
"prop": "foo",
"list": [
{ "key": "1" },
{ "key": "2" },
{ "key": "3" },
{ "key": "4" },
{ "key": "5" },
{ "key": "6" }
]
},
{ ...item }
{ ...item }
]
I.e. to process all the A
, B
and C
tags in order and into the same array.
I am using xml2json
, which uses node-expat
to parse the file. Is this at all possible using node-expat
or any existing npm
package? The reason I ask is because I don't want to be writing my own parser in a compiled language if at all possible.
Thanks