node-xml2js
node-xml2js copied to clipboard
charkey cannot match name of child node
It appears that if the charkey matches the name of a child node the return value breaks in a very interesting way. Took me a while to figure out what was going on.
In this example:
const test = `
<meters>
<meter>
<key>engine</key>
<value>1747</value>
<units>hrs</units>
</meter>
</meters>`;
With these options:
await xml2js.parseStringPromise(test, {
explicitArray: false,
charkey: 'value',
});
Produces this result:
{
"meters": {
"meter": {
"value": "\n \n ,1747\n \n ",
"key": "engine",
"units": "hrs"
}
}
}
I'm not exactly sure what the right behaviour is here, but possibly worth warning in the docs.