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

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

Open mariusa opened this issue 5 years ago • 0 comments

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": []
}

mariusa avatar Oct 16 '20 11:10 mariusa