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

`stopNodes` doesn't work with `removeNSPrefix` #607

Closed candrews closed 1 year ago

candrews commented 1 year ago

Description

stopNodes doesn't work with xml documents that use namespaces when removeNSPrefix is set. This issue is documented by the comment at https://github.com/NaturalIntelligence/fast-xml-parser/blob/v4.2.7/src/xmlparser/OrderedObjParser.js#L308

The stopNodes feature should work with xml that uses namespaces with removeNSPrefix=true.

Input

<issue><title>test 1</title><namespace:fix1><p>p 1</p><div class="show">div 1</div></namespace:fix1></issue>

Code

    const xmlData = `<issue><title>test 1</title><namespace:fix1><p>p 1</p><div class="show">div 1</div></namespace:fix1></issue>`;
    const expected = {
      "issue": {
        "title": "test 1",
        "fix1": "<p>p 1</p><div class=\"show\">div 1</div>"
      }
    };

    const options = {
      attributeNamePrefix: "",
      ignoreAttributes: false,
      parseAttributeValue: true,
      removeNSPrefix: true,
      stopNodes: ["issue.fix1"]
    };
    const parser = new XMLParser(options);
    let result = parser.parse(xmlData);

    // console.log(JSON.stringify(result,null,4));
    expect(result).toEqual(expected);

Output

Error: Unexpected end of fix1

expected data

    const expected = {
      "issue": {
        "title": "test 1",
        "fix1": "<p>p 1</p><div class=\"show\">div 1</div>"
      }
    };

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.

amitguptagwl commented 1 year ago

Fixed in v4.3.0