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

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

Closed
5 of 6 tasks
ATXadam opened this issue Sep 15, 2023 · 2 comments
Closed
5 of 6 tasks

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

ATXadam opened this issue Sep 15, 2023 · 2 comments

Comments

@ATXadam
Copy link

ATXadam commented Sep 15, 2023

  • Are you running the latest version?
  • Have you included sample input, output, error, and expected output?
  • Have you checked if you are using correct configuration?
  • Did you try online tool?

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?

  • Yes
  • No

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

@github-actions
Copy link

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
Copy link
Author

ATXadam commented Sep 15, 2023

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>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant