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

xmlns attribute added to the root element is shown on its child elements #1

Closed
lazorkon opened this issue Feb 14, 2020 · 1 comment
Closed
Assignees
Labels
bug Something isn't working

Comments

@lazorkon
Copy link

Describe the bug
xmlns attribute added to the root element is shown on its child elements.
Attributes with other names are shown correctly.

NOTE: Problem appears when attributes are added via att method:
.att({ xmlns: 'http://example.com', x: 0 })

There is no problem when attributes are added via ele method:
.ele('SomeRootTag', { xmlns: 'http://example.com', x: 0 })

To Reproduce

const builder = require('xmlbuilder2');

const xml = builder.create()
.dec({ version: '1.0', encoding: 'UTF-8', })
.ele('SomeRootTag')
.att({ xmlns: 'http://example.com', x: 0 })

.ele('foo')
.att({ a: 'A1', x: 1 })
.ele('subFoo')
.att({ a: 'A2', x: 1.1 })
.up()
.up()

.ele('bar')
.att({ b: 'B', x: 2 })

console.log(xml.end({ prettyPrint: true }));

Actual output - xmlns attribute on second elements

<?xml version="1.0" encoding="UTF-8"?>
<SomeRootTag x="0">
  <foo xmlns="http://example.com" a="A1" x="1">
    <subFoo a="A2" x="1.1"/>
  </foo>
  <bar xmlns="http://example.com" b="B" x="2"/>
</SomeRootTag>

Expected behavior
Expected output - xmlns attribute on root element

<?xml version="1.0" encoding="UTF-8"?>
<SomeRootTag xmlns="http://example.com" x="0">
  <foo a="A1" x="1">
    <subFoo a="A2" x="1.1"/>
  </foo>
  <bar b="B" x="2"/>
</SomeRootTag>

Version:

  • node.js: [e.g. 8.16.2]
  • xmlbuilder2 [e.g. 1.1.1]

Additional context
Previous version of xmlbuilder 13.0.2 works correctly - (xmlns attribute on root element)

@lazorkon lazorkon added the bug Something isn't working label Feb 14, 2020
@oozcitak
Copy link
Owner

Thank you, I'm looking into it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants