Open
Description
Running
const util = require('util');
const xml2js = require('xml2js');
const xml = `
<?xml version="1.0" encoding="UTF-8"?>
<test xmlns="http://example.com/namespace">
<value1>value1</value1>
<value2></value2>
<value3 xmlns="http://example.com/namespace">value3</value3>
<value4 xmlns="http://example.com/namespace"></value4>
</test>
`;
(async () => {
const result = await new xml2js.Parser({
emptyTag: '--EMPTY--',
explicitArray: false
}).parseStringPromise(xml);
console.log(util.inspect(result, false, null));
})();
prints following
{
test: {
'$': { xmlns: 'http://example.com/namespace' },
value1: 'value1',
value2: '--EMPTY--',
value3: { _: 'value3', '$': { xmlns: 'http://example.com/namespace' } },
value4: { '$': { xmlns: 'http://example.com/namespace' } }
}
}
expected result for value4
{ _: '--EMPTY--', '$': { xmlns: 'http://example.com/namespace' } }
Metadata
Metadata
Assignees
Labels
No labels