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

Creating an XML document then converting to object adds prettification whitespace to JSON #118

Open
ethan-xd opened this issue Feb 3, 2022 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@ethan-xd
Copy link

ethan-xd commented Feb 3, 2022

Describe the bug
Creating an XML document from a prettified XML string, with whitespaces and newlines, then converting to a JS object, leaves in /n and whitespaces from the prettification.

To Reproduce
Given part of an XML string:

...
<Point>
  <coordinates>
    144.9690641,-37.8175873,0
  </coordinates>
</Point>
...

...viewing it with:

console.log(JSON.stringify(create(someXMLString).end({ format: 'object' })));

...will show:

...
"Point":{"coordinates":"\n            144.9690641,-37.8175873,0\n          "}
...

Expected behavior
Parsing:

...
<Point>
  <coordinates>
    144.9690641,-37.8175873,0
  </coordinates>
</Point>
...

...should return:

...
"Point":{"coordinates":"144.9690641,-37.8175873,0"}
...

Version:

  • node.js: [v16.4.1]
  • xmlbuilder2 [3.0.2]

Additional context
This issue was found when working with the KML format.

@ethan-xd ethan-xd added the bug Something isn't working label Feb 3, 2022
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