Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stopNodes doesn't work with removeNSPrefix #607

Closed
5 of 7 tasks
candrews opened this issue Aug 30, 2023 · 2 comments
Closed
5 of 7 tasks

stopNodes doesn't work with removeNSPrefix #607

candrews opened this issue Aug 30, 2023 · 2 comments

Comments

@candrews
Copy link
Contributor

candrews commented Aug 30, 2023

  • Are you running the latest version?
  • Have you included sample input, output, error, and expected output?
  • Have you checked if you are using correct configuration?
  • Did you try online tool?

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?

  • Yes
  • No
  • Maybe

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

@github-actions
Copy link

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.

@candrews candrews changed the title Support namespaces with stopNodes stopNodes doesn't work with removeNSPrefix Aug 30, 2023
candrews added a commit to candrews/fast-xml-parser that referenced this issue Aug 30, 2023
candrews added a commit to candrews/fast-xml-parser that referenced this issue Aug 30, 2023
Signed-off-by: Craig Andrews <candrews@integralblue.com>
candrews added a commit to candrews/fast-xml-parser that referenced this issue Sep 5, 2023
Signed-off-by: Craig Andrews <candrews@integralblue.com>
candrews added a commit to candrews/fast-xml-parser that referenced this issue Sep 5, 2023
Signed-off-by: Craig Andrews <candrews@integralblue.com>
candrews added a commit to candrews/fast-xml-parser that referenced this issue Sep 8, 2023
Signed-off-by: Craig Andrews <candrews@integralblue.com>
amitguptagwl pushed a commit that referenced this issue Sep 10, 2023
Signed-off-by: Craig Andrews <candrews@integralblue.com>
@amitguptagwl
Copy link
Member

Fixed in v4.3.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants