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.43k stars 297 forks source link

Missing `entities` option in XMLBuilder #655

Open marcoreni opened 1 month ago

marcoreni commented 1 month ago

Description

Builder has an "entities" property that specifies some replacement on entities: https://github.com/NaturalIntelligence/fast-xml-parser/blob/96f75016ba2434006d4120517f47096c80df4081/src/xmlbuilder/json2xml.js#L25

However, this property is not documented nor on XMLBuilderProperties: https://github.com/NaturalIntelligence/fast-xml-parser/blob/96f75016ba2434006d4120517f47096c80df4081/src/fxp.d.ts#L230

It seems possible to override it, but I'm not sure if this is meant to be "internal" or can be exposed/documented.

Input

Code


const builder = new XMLBuilder({
// Object literal may only specify known properties, and 'entities' does not exist in type 'XmlBuilderOptions'.ts(2353)
    entities: [
        { regex: new RegExp("&", "g"), val: "&" }, //it must be on top
        { regex: new RegExp(">", "g"), val: "FOO" },
        { regex: new RegExp("<", "g"), val: "BAR" },
        { regex: new RegExp("'", "g"), val: "HELLO" },
    ],
});

Output

expected data

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 1 month 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 1 month ago

don't remember exactly, but I wanted to keep it n the same as parser