NaturalIntelligence / fast-xml-parser

Validate XML, Parse XML and Build XML rapidly without C/C++ based libraries and no callback.

Home Page:https://naturalintelligence.github.io/fast-xml-parser/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

XMLBuilder line break behavior change after upgrading

afbpinheiro opened this issue · comments

  • 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>

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.

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

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

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.