NaturalIntelligence / fast-xml-parser

Validate XML, Parse XML and Build XML rapidly without C/C++ based libraries and no callback.
https://naturalintelligence.github.io/fast-xml-parser/
MIT License
2.43k stars 297 forks source link

Attribute value of true is not rendering correctly in XMLBuilder #611

Closed ATXadam closed 9 months ago

ATXadam commented 9 months ago

Description

When using XMLBuilder to render an attribute with a value (string or bool) of 'true', XMLBuilder does not render the value as a string in the attribute.

Input

{"test": {"@_isTrue": true}}

Code

const { XMLBuilder } = require('fast-xml-parser')
let builder = new XMLBuilder({ ignoreAttributes: false});
builder.build({"test": {"@_isTrue": true}})

Output

<test isTrue></test>

expected data

<test isTrue="true"></test>

Would you like to work on this issue?

Bookmark this repository for further updates. Visit SoloThought to know about recent features.

github-actions[bot] commented 9 months ago

We're glad you find this project helpful. We'll try to address this issue ASAP. You can vist https://solothought.com to know recent features. Don't forget to star this repo.

ATXadam commented 9 months ago

After starting to look through the code, I saw suppressBooleanAttributes in the XMLBuilder options, setting this to false resolves the issue. https://naturalintelligence.github.io/fast-xml-parser/ "Allow Boolean Attributes" did not set this flag going from JSON to XML it appears.

const { XMLBuilder } = require('fast-xml-parser');
let builder = new XMLBuilder({ ignoreAttributes: false, suppressBooleanAttributes: false});
builder.build({"test": {"@_isTrue": true}});

Yields

<test isTrue="true"></test>