node-xml2js icon indicating copy to clipboard operation
node-xml2js copied to clipboard

charkey cannot match name of child node

Open scottwillman opened this issue 4 years ago • 0 comments

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.

scottwillman avatar Oct 16 '22 05:10 scottwillman