I am using fast-xml-parser and have a challenge in preserving leading zeros. I have simplified the example to the core of my problem.
I would like to preserve these leading zeros in the value of an item in the xmlOutput. I want xmlOutput to eventually equal xmlInput, so xmlOutput should be
<item>08</item> instead of <item>8</item> which is what I get now.
How can I configure that?
Run the code beneath as follows: node xmlparse
const { XMLParser, XMLBuilder, XMLValidator } = require("fast-xml-parser");
const options = {
parseTrueNumberOnly: true //if true then values like "+123", or "0123" will not be parsed as number.
};
const xmlInput = '<item>08</item>';
console.log(xmlInput);
const parser = new XMLParser(options);
let jsonData = parser.parse(xmlInput);
console.log(JSON.stringify(jsonData));
const builder = new XMLBuilder();
const xmlOutput = builder.build(jsonData,options)
console.log(xmlOutput);
I expected <item>08</item> but I got <item>8</item>