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

unpairedTags matching requires paired tag sibling to work #562

Closed
4 of 6 tasks
nibk opened this issue Apr 18, 2023 · 2 comments
Closed
4 of 6 tasks

unpairedTags matching requires paired tag sibling to work #562

nibk opened this issue Apr 18, 2023 · 2 comments

Comments

@nibk
Copy link

nibk commented Apr 18, 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

unpairedTags option doesn't work if not followed immediately by a paired tag, its parent consumes the next sibling.

Input

<root>
  <a>
    <unpaired>
  </a>
  <b>whatever</b>
</root>

Code

As per the API example:

const xmlDataStr = `
<root>
	<a>
		<unpaired>
	</a>
	<b>whatever</b>
</root>
`;

const options = {
  unpairedTags: ["unpaired"]
};
const parser = new XMLParser(options);
const output = parser.parse(xmlDataStr);

Output

{
        "root": {
                "a": {
                        "unpaired": "",
                        "b": "whatever"
                }
        }
}

Correct structure can be generated by changing input to:

<root>
  <a>
    <unpaired><pair>foo</pair>
  </a>
  <b>whatever</b>
</root>

which triggers correct parsing, eg:

{
        "root": {
                "a": {
                        "unpaired": "",
                        "pair": "foo"
                },
                "b": "whatever"
        }
}

expected data

{
        "root": {
                "a": {
                        "unpaired": "",
                },
                "b": "whatever"
        }
}

Would you like to work on this issue?

  • Yes
  • No
@github-actions
Copy link

I'm glad you find this repository helpful. I'll try to address your issue ASAP. You can watch the repo for new changes or star it.

@amitguptagwl
Copy link
Member

This issue is fixed in v4.2.2,
Please visit solothought to read about latest features released.

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