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.53k stars 303 forks source link

Introduce isObject option for unpaired tags #630

Open c100k opened 9 months ago

c100k commented 9 months ago

Description

Unpaired tags are parsed into an empty string. But in some cases, it should be something else. Like an object for example. In the same style of [`isArray`](https://github.com/NaturalIntelligence/fast-xml-parser/blob/master/docs/v4/2.XMLparseOptions.md#isarray), we could introduce an `isObject` option, working the same way. ### Input

Let's take for example the following XML:

<Response>
    <id>123</id>
    <dataSet/>
</Response>

Code

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

Output

It gives the following output:

{
    "?xml": "",
    "Response": {
        "id": 123,
        "dataSet": ""
    }
}

expected data

I would instead expect the following result:

{
    "?xml": "",
    "Response": {
        "id": 123,
        "dataSet": {}
    }
}

Would you like to work on this issue?

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

github-actions[bot] commented 9 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 9 months ago

I've took care of this in v5.