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

Number 0 is omitted when converting object to xml #21

Closed
linkeo opened this issue Jun 11, 2020 · 3 comments · Fixed by #22
Closed

Number 0 is omitted when converting object to xml #21

linkeo opened this issue Jun 11, 2020 · 3 comments · Fixed by #22
Assignees
Labels
bug Something isn't working

Comments

@linkeo
Copy link

linkeo commented Jun 11, 2020

Describe the bug
When converting object to xml, it's not expected to convert number 0 into empty content.

To Reproduce

const { create } = require('xmlbuilder2');

const xml = create().ele({ value: 0 }).end()

will produce

<?xml version="1.0"?><root><value/></root>

Expected behavior

It should be

<?xml version="1.0"?><root><value>0</value></root>

Version:

  • node.js: [12.13.0]
  • xmlbuilder2 [2.1.2]

Additional context
Add any other context about the problem here.

@linkeo linkeo added the bug Something isn't working label Jun 11, 2020
@linkeo
Copy link
Author

linkeo commented Jun 11, 2020

@oozcitak Is it ok to change this condtion to else if (value != null)

lastChild.ele(val)
} else if (val) {
// leaf element node with a single text node

@oozcitak
Copy link
Owner

Yes that should do it. Would you like to send a PR?

@linkeo
Copy link
Author

linkeo commented Jun 11, 2020

@oozcitak ok, i will send it soon

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

Successfully merging a pull request may close this issue.

2 participants