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.49k stars 302 forks source link

Is it possible to stack attributes when formatting xml #545

Closed nickminutello closed 1 year ago

nickminutello commented 1 year ago

When an xml element has many attributes, the current format:true produces an exceedingly long line.

Is it possible to produce something like this:

<ze-element attribute01="something"
                      attribute02="something else"
                      attribute03="something else again"
                      attribute04="different"
                      attribute05="different again"
                      attribute06="another one"
                      attribute07="more"
                      attribute08="more still"
                      attribute09="here is another"
                      attribute10="and another"
                      attribute11="and another" />

Many thanks

github-actions[bot] commented 1 year ago

I'm glad you find this repository helpful. I'll try to address your issue ASAP. You can watch the repo for new changes or star it.

amitguptagwl commented 1 year ago

Sorry, currently, there is no feature which can help you

nickminutello commented 1 year ago

Is it something that could be added ? (e.g. if more than n attributes, stack vertically)

amitguptagwl commented 1 year ago

You can use attributeValueProcessor to stack the values of all the attributes. But you can't skip other attributes. Probably I can think about a feature to introduce skipAttribute function. And then a event like onTagClose to add new attribute.

But it will take time. If you want to work you can raise PR. It'll be easy.

amitguptagwl commented 1 year ago

updateTag option is added to the parser v4.2 to change attributes. Check solothought post for detail example.