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

removeNSPrefix option doesn't work #596

Closed prithwirajbose closed 1 year ago

prithwirajbose commented 1 year ago

Description

As per Changelog, ignoreNameSpace option in V3 is change to removeNSPrefix in V4. However, this option doesn't seem to work. This is one of the critical options because it changes the output JSON tagnames completely, for an input XML which has namespaces in tag names.

Input

<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> <soapenv:Header/> <soapenv:Body><Data>Hello</Data></soapenv:Body></soapenv:Envelope>

Code

const { XMLParser } = require("fast-xml-parser");
const fastXmlParser = new XMLParser();
var xmlParserOptions = {
    attrPrefix: "",
    textNodeName: "text",
    ignoreTextNodeAttr: false,
    removeNSPrefix: true,
    textNodeConversion: false
};
var json = fastXmlParser.parse(xmlBody, xmlParserOptions);

Output

{"?xml":"","soapenv:Envelope":{"soapenv:Header":"","soapenv:Body":{ "Data": "Hello" }}}

expected data

{"?xml":"","Envelope":{"Header":"","Body":{ "Data": "Hello" }}}

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

prithwirajbose commented 1 year ago

Can someone please provide an update?

amitguptagwl commented 1 year ago

@prithwirajbose options are supposed to be passed in constructor not the parsing method. Check https://solothought.com/tutorial/fast-xml-parser-4.2-features/ for a few example how the library is supposed to be used.

Reopen the issue if you still face the problem.