Open lengerrong opened 3 years ago
The parsed json object is like:
{
'a:p': {
'#name': 'a:p',
'$$': [ [Object], [Object], [Object], [Object], [Object] ],
'a:pPr': [ [Object] ],
'a:r': [ [Object], [Object] ],
'a:br': [ [Object] ],
'a:endParaRPr': [ [Object] ]
}
}
except '#name', '$$' will be consider as invalid TagName as well.
it seems like xml2js.Builder didn't support preserveChildrenOrder:true option yet.
The author of the library specifies this in the docs: At the moment, a one to one bi-directional conversion is guaranteed only for default configuration, except for attrkey, charkey and explicitArray options you can redefine to your taste.
sad but true.
HI, is there any work around for this?
preserveChildrenOrder (default false): Modifies the behavior of explicitChildren so that the value of the "children" property becomes an ordered array. When this is true, every node will also get a #name field whose value will correspond to the XML nodeName, so that you may iterate the "children" array and still be able to determine node names. The named (and potentially unordered) properties are also retained in this configuration at the same level as the ordered "children" array. Added in 0.4.9.
when we parser xml string with {preserveChildrenOrder:true} option, each node will add a "#name" field. but when we try to builder the js object back to string again, we got Error:
Error: Invalid character in name at XMLStringifier.module.exports.XMLStringifier.assertLegalName (node_modules/xml2js/node_modules/xmlbuilder/lib/XMLStringifier.js:213:15)
reproduce code: