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

Error occurs when using empty nodes: Text data outside of root node #699

Open
cheenamalhotra opened this issue Nov 22, 2023 · 3 comments
Open

Comments

@cheenamalhotra
Copy link

cheenamalhotra commented Nov 22, 2023

Here's a repro:

var xml2js = require('xml2js');
var data = '<p>hello world</p><p> </p><p>&nbsp;</p>';
var parser = new xml2js.Parser();
parser.parseString(data, function (err, result) {
    console.dir(result);
});
Error: Text data outside of root node.
Line: 0
Column: 33
Char: &

Alternatives that work

  • <div><p>hello world</p><p> </p><p>&nbsp;</p></div> (wrap into root node)
  • <p>hello world</p><p>&nbsp;</p><p>something</p> (not use empty string)
    • This reads only first node and doesn't fail with error, so I'm not sure if this is also supposed to fail, due to absence of root node?

It would be good if expected behaviors are documented.

@Leonidas-from-XIV
Copy link
Owner

Leonidas-from-XIV commented Nov 22, 2023 via email

@cheenamalhotra
Copy link
Author

cheenamalhotra commented Nov 22, 2023

If by well-formed XML, you mean a parent root node is required, that should be something to begin with.
And secondly, if multiple root nodes are not allowed, it should consistently fail.

@Leonidas-from-XIV
Copy link
Owner

Leonidas-from-XIV commented Nov 22, 2023 via email

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