Closed julienloizelet closed 3 years ago
I found a solution, so I will close this.
Using this code :
const xml2js = require('xml2js');
const builder = new xml2js.Builder({
});
const sampleObject1 = {
"Lines": {
"Line": [
{
"bar": [
"bazline1"
],
"Sublines":
{
"Subline": [
{
"sublinecontent": [
"1"
]
},
{
"sublinecontent": [
"2"
]
}
]
}
},
{
"bar": [
"bazline2"
]
},
{
"bar": [
"bazline3"
]
}
]
}
}
console.log(`Sample : \n${builder.buildObject(sampleObject1)}\n`);
the output result is as expected :
Sample :
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Lines>
<Line>
<bar>bazline1</bar>
<Sublines>
<Subline>
<sublinecontent>1</sublinecontent>
</Subline>
<Subline>
<sublinecontent>2</sublinecontent>
</Subline>
</Sublines>
</Line>
<Line>
<bar>bazline2</bar>
</Line>
<Line>
<bar>bazline3</bar>
</Line>
</Lines>
Hi,
When I try this code :
the output result is
As you can see, there is only one node
Lines
which contains 3 children nodesLine
: this is what I expected becauseLines
is an array ofLine
in the initial json.BUT : there are multiple (2) nodes
Sublines
where I was expecting something like :Indeed,
Sublines
is an array ofSubline
in the initial json : so I was expectingSubline
nodes to be children of a uniqueSublines
node.Well, is there a way to get the result I want ?