I'm using fast-xml-parser to create xml documents from json. In the examples they show how to create an element with attributes
const jsOrderedObj = [
{
"?textinfo": [
{
"#text": ""
}
],
":@": {
"@_whitespace": true,
"@_is": true,
"@_allowed": true
}
}
];
const options = {
ignoreAttributes: false,
preserveOrder: true,
allowBooleanAttributes: true,
suppressBooleanAttributes: true
};
const builder = new XMLBuilder(options);
const output = builder.build(result);
result:
<?textinfo whitespace is allowed?>
And examples of how to create an XML document with child elements:
const xmlData = {
'foo': {
'bar': 'data',
'bar2': 'data2',
'bar3': 'data3',
'bar4': 'data4',
}
}
const builder = new XMLBuilder({});
const output = builder.build(xmlData);
result:
<foo><bar>data</bar><bar2>data2</bar2><bar3>data3</bar3><bar4>data4</bar4></foo>
Now my question is, how should I define my json, to get both attributes and child elements in my xml, like this:
<foo whitespace is allowed><bar>data</bar><bar2>data2</bar2><bar3>data3</bar3><bar4>data4</bar4></foo>