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

XMLBuilder Incorrectly Serializes String "true" as Boolean Attribute #656

Closed
5 of 6 tasks
Undefined01 opened this issue May 27, 2024 · 4 comments
Closed
5 of 6 tasks

Comments

@Undefined01
Copy link

  • 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 serialize attributes with the string value "true", they are incorrectly serialized as Boolean attributes, regardless of the Allow Boolean Attributes option's state. This results in an output where the attribute appears without an explicit value, which differs from the expected behavior where the attribute should explicitly show "true".

Input

{
    "test": {
        "@_property1": "true",
        "@_property2": "false"
    }
}

Code

const fxp = require('fast-xml-parser');
const opts = {
    ignoreAttributes: false
};
const xmlObj = {
    test: {
        "@_property1": "true",
        "@_property2": "false"
    }
};
const builder = new fxp.XMLBuilder(opts);
console.log(builder.build(xmlObj));

Output

<?xml version="1.0"?>
<test property1 property2="false"></test>

expected data

<?xml version="1.0"?>
<test property1="true" property2="false"></test>

Would you like to work on this issue?

  • Yes
  • No

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

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.

@amitguptagwl
Copy link
Member

@Undefined01
Copy link
Author

Setting suppressBooleanAttributes to false solves this problem.

I think it is kind of unintuitive. It's odd that {"@_Property": "true"} gets treated as a boolean attribute and suppressed, yet {"@_Property": false} and {"@_Property": "false"} are not affected in the same way. Besides, I would expect they will not be regarded as boolean attributes and suppressed after setting allowBooleanAttributes to false.

@wodepig
Copy link

wodepig commented Sep 3, 2024

设置为 可解决此问题。suppressBooleanAttributes``false

我认为这有点不直观。奇怪的是,它被视为 boolean 属性并被抑制,但 并且没有以相同的方式受到影响。此外,我希望它们不会被视为布尔属性并在设置为 false 后被抑制。{"@_Property": "true"}``{"@_Property": false}``{"@_Property": "false"}``allowBooleanAttributes

is worked ,thanks

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

3 participants