Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

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

Open
jonikorhonen opened this issue Jun 5, 2022 · 0 comments · 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 · 0 comments · 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' } }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant