node-xml2js
node-xml2js copied to clipboard
emptyTag option considers whitespace strings empty.
Version 0.4.23
Hello. I'm having trouble keeping whitespace nodes while having the emptyTag option set to {}. Here's a code snippet:
const {inspect} = require('util');
const xml2js = require('xml2js')
const opt1 = {
explicitArray: false,
includeWhiteChars: true,
};
const opt2 = {
...opt1,
emptyTag: {},
}
const parser1 = new xml2js.Parser(opt1);
const parser2 = new xml2js.Parser(opt2);
const body = `
<?xml version="1.0" encoding="UTF-8" ?>
<root>
<description> </description>
</root>
`;
(async function test() {
const result1 = await parser1.parseStringPromise(body);
const result2 = await parser2.parseStringPromise(body);
console.log(inspect(result1, {showHidden: false, depth: null})) // { root: { description: ' ' } }
console.log(inspect(result2, {showHidden: false, depth: null})) // { root: { description: {} } }
})();
The emptyTag option, if set to something, seems to trim whitespace, even if the includeWhiteChars option is set to true.