Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Bug - Parsing empty tag with namespace doesn't return empty value #647

Open
jonikorhonen opened this issue Jun 5, 2022 · 1 comment · May be fixed by #712
Open

Bug - Parsing empty tag with namespace doesn't return empty value #647

jonikorhonen opened this issue Jun 5, 2022 · 1 comment · May be fixed by #712

Comments

@jonikorhonen
Copy link

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' } }
@zmw85
Copy link

zmw85 commented Jan 23, 2025

Found same issue here, it looks like it doesn't treat tags as empty when there is a tag attribute presented, not just limit to "xmlns" attribute.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants