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.45k stars 296 forks source link

XMLBuilder line break behavior change after upgrading #605

Open afbpinheiro opened 11 months ago

afbpinheiro commented 11 months ago

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[bot] commented 11 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.

amitguptagwl commented 10 months ago

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 commented 10 months ago

@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 commented 10 months ago

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.