-
Notifications
You must be signed in to change notification settings - Fork 605
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: Text data outside of root node. #118
Comments
This looks like your XML data is invalid. Could it be that it looks like this? <root>foo</root>
bar |
Oh I'm sure that the XML is screwed up, but I'm wondering why it's throwing an error event instead of using the returned "err" object? If this is intended behavior, how do I handle this parsing error so bad XML doesn't crash my program? |
Hey man, could you take a look at my previous question and advise? I'd just like to be able to handle this XML parsing error. |
Same issue here. We have to parse XML coming from outside sources and some of that external XML is bad. Looks like the exception originates in sax:
|
Well you could wrap it in a try-catch. But I agree, this looks quite like a bug in xml2js and should be handled by the |
Found it. It's a subtle thing in the interaction with Sax. Here's a Gist of what I added: https://gist.github.com/toddrbryan/8460378 I can do a pull request if you wish. Here's the sequence of events as I understand it: Sax begins parsing bad XML which has multiple errors. It throws its custom error event (not a Node EventEmitter event) and xml2js catches it, decides if it has already thrown a single error for this sax parser, and then throws its own error event accordingly. But the Sax error isn't cleared by calling saxParser.resume() so that the next time Sax enters write(), it throws a JS error (as it does when a previous error hasn't been cleared by resume() ). Additionally, xml2js does not throw an end event when the saxParser emits an onend, causing parseString() to hang forever. To fix that I added a handler for Sax's end event in xml2js. |
@toddrbryan 👍 If you add a regression test, I'd be more than happy to merge your pull request! |
@toddrbryan @Leonidas-from-XIV How's this coming along? |
Hey there - I'm sorry, I let this slip my mind. I'll get a test going and get you a Best - Todd On Mon, Mar 10, 2014 at 1:36 PM, Timo Sand notifications@github.com wrote:
|
Great stuff @toddrbryan. Looking forward to getting my grubby hands on this at some point. |
Needed to modify the package.json to ensure the Xml2Js package was only updating to the latest v0.2.x as there is a defect in 0.4.x where malformed XML throws an exception. See this issue: Leonidas-from-XIV/node-xml2js#118
Needed to modify the package.json to ensure the Xml2Js package was only updating to the latest v0.2.x as there is a defect in 0.4.x where malformed XML throws an exception. See this issue: Leonidas-from-XIV/node-xml2js#118 There is also an issue using coffee script 1.7.x, the coffee script only compiles going unto 1.6.x so I have made that modification also.
This was merged couple days ago and is part of 0.4.2, so closing that issue now. |
When parsing I occasionally receive this:
I am using the module in the "Shoot-and-forget" method:
Am I missing something or is this a bug?
The text was updated successfully, but these errors were encountered: