Leonidas-from-XIV / node-xml2js

XML to JavaScript object converter.
MIT License
4.87k stars 601 forks source link

[parser] empty element results in "\n \n " #588

Open mariusa opened 3 years ago

mariusa commented 3 years ago

Parsing an empty element should result in an empty array, not string with \n's I see how this makes sense for a text node. Is there a way to get an empty array instead?

 const xml2js = require('xml2js')
    const xmlbuilder = new xml2js.Builder()
    const xmlparser = new xml2js.Parser()

    let x = `
    <result timestamp="1602848610696">
    <items>

    </items>
    </result>
`
    let res = await xmlparser.parseStringPromise(x)
    res = res.result
    l('parser result', JSON.stringify(res))

outputs

parser result {
    "$": {
        "timestamp": "1602848610696"
    },
    "items": [
        "\n                      \n    "
    ]
}

Expected:

parser result {
    "$": {
        "timestamp": "1602848610696"
    },
    "items": []
}