Skip to content

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

Open
@ethan-xd

Description

@ethan-xd

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.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions