Closed dobesv closed 3 years ago
I wanted to have an element with two child elements in it, but I got two elements each with one child.
> console.log(new xml2js.Builder().buildObject({ aaa: { header: [{rhi: [{v: ['1']}, {mid: ['123']}]}]}})) <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <aaa> <header> <rhi> <v>1</v> </rhi> <rhi> <mid>123</mid> </rhi> </header> </aaa>
I expected to get:
> console.log(new xml2js.Builder().buildObject({ aaa: { header: [{rhi: [{v: ['1']}, {mid: ['123']}]}]}})) <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <aaa> <header> <rhi> <v>1</v> <mid>123</mid> </rhi> </header> </aaa>
Interestingly, when I pass this through parse it merges the two elements back together:
> new xml2js.Parser({explicitArray: true}).parseStringPromise(s).then(d => JSON.stringify(d, null, 2)).then(console.log) Promise { <pending> } > { "aaa": { "header": [ { "rhi": [ { "v": [ "1" ] }, { "mid": [ "123" ] } ] } ] } }
Ah ... hmm I think I was just really confused about how the javascript objects are formatted. The above is probably the correct behavior.
I wanted to have an element with two child elements in it, but I got two elements each with one child.
I expected to get:
Interestingly, when I pass this through parse it merges the two elements back together: