Leonidas-from-XIV / node-xml2js

XML to JavaScript object converter.
MIT License
4.88k stars 602 forks source link

empty tags result in [ '\015\n ' ] #515

Closed deeyonn closed 2 years ago

deeyonn commented 5 years ago

EDIT I am able to work around the issue by doing JSON.stringify(jsonObj).match(/\\r\\n/)

Hi, when I parse this xml: <tag1> </tag1>

the jsonObj i get is: { tag1: [ '\015\n ' ] } when it should be: { tag1: [{}] } or: { tag1: "" }

i'm trying to use lodash's _.forEach() to aggregate Object.keys(jsonObj).length for a few tag occurrences, but the resulting { tag1: [ '\015\n ' ] } JSON throws me an error when i do Object.keys(jsonObj).length

knoxcard commented 5 years ago

Try this...

var builder = new xml2js.Builder({
     renderOpts: {
        pretty: false
    }
});

This is related... https://github.com/Leonidas-from-XIV/node-xml2js/issues/111

knoxcard commented 5 years ago

@deeyon - close issue?