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 line break behavior change after upgrading #605

Open
4 tasks done
afbpinheiro opened this issue Aug 22, 2023 · 4 comments
Open
4 tasks done

XMLBuilder line break behavior change after upgrading #605

afbpinheiro opened this issue Aug 22, 2023 · 4 comments

Comments

@afbpinheiro
Copy link

afbpinheiro commented Aug 22, 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

After upgrading from 3.17.4 to 4.2.7 there was an unexpected change in how XMLBuilder behaved regarding putting line breaks in empty elements.

Input

Code

const builder = new XMLBuilder({
        format: true,
});
const xml = builder.build({ root: { profile: [] } });
console.log(xml);

Output

<root></root>

expected data

<root>
</root>
@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.

@amitguptagwl
Copy link
Member

It is difficult to decide sometimes what behavior should be kept as different user has different needs. And introducing so many options to control the formatting also can confuse users to take right decision. But I'll check what best can be done

@afbpinheiro
Copy link
Author

@amitguptagwl thanks for your response.

I would say, based on the docs definition (https://github.com/NaturalIntelligence/fast-xml-parser/blob/master/docs/v4/3.XMLBuilder.md#format): "By default, parsed XML is single line XML string. By format: true, you can format it for better view", the current output is not correct/expected.

@amitguptagwl
Copy link
Member

Honestly speaking <root></root> is my favourite. Just think it as a json property, we don't put comma (value ending indicator) in another line. So probably, I've done it for my own preference, I don't remember. But I'll check what I can do to. Probably, custom formatting themes can be introduced, I'll keep mine, you keep your own. And library will support standard by default.

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

2 participants