Skip to content

unpairedTags matching requires paired tag sibling to work #562

@nibk

Description

@nibk
  • 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions