sabre-io / xml

sabre/xml is an XML library that you may not hate.
http://sabre.io/xml/
BSD 3-Clause "New" or "Revised" License
516 stars 77 forks source link

Sabre/Xml/ParseException explanation, troubleshooting or error handling - [question] #163

Closed danswiser closed 5 years ago

danswiser commented 5 years ago

I'm stuck trying to figure out what's causing the below error:

Sabre/Xml/ParseException with message 'We hit the end of the document prematurely. This likely means that some parser "eats" too many elements. Do not attempt to continue parsing.'

The error is only ever triggered when I run the parseInnerTree() function on my XML string and seems to always error on a specific element. When I check that element outside of my script, nothing seems out of place and it's valid XML.

From a few searches, it seems like #140 could be similar but I'm not using any type of KeyValue implementation.

I'm sorry for the lack of more specifics, but I don't understand where to start yet. I was first looking to dump additional details like what line of XML the script is at the time the error is thrown or actually showing the full element which caused the error but I couldn't find much.

evert commented 5 years ago

Hi @danswiser ,

Could you please share a script that reproduces the issue? It would really help with this.

danswiser commented 5 years ago

Thanks for the quick response.

Unfortunately the XML contains sensitive company data and I can't share that.

I should be able to privately share the code after I remove some information if that would help?

evert commented 5 years ago

It's not just me looking at this though. It's definitely more helpful to have it there.

All we need really is a testcase that can trigger the bug, so it doesn't have to be the exact XML you're using. You can modify the source data until the error pops up?

danswiser commented 5 years ago

Is there a way to dump the last line which was being processed before or after the error is thrown? If I can at least see "into" the Reader class when it's failing I can keep troubleshooting.

Here's some code and an example of how the XML file is structured: https://gist.github.com/danswiser/fc1d4e85fabd5e4c200ebf885e474226

To describe what's going on, I'm converting an XML file which shows the status of multiple queues in a call center. Many Queue's can have many Groups of Agents and each Agent belongs to one Group.

I have 4-5 XML responses from multiple endpoints which have G Elements for each Group with a list of Queues and Agents they are tied to. Each response is parsed using this package into Agent, Group and Queue classes.

In the Processor class, the process() function is where this package starts to get used.

evert commented 5 years ago

What happens if you remove: $reader->next(); // Required

Calling ->next is required, but parseInnerTree should already call it.

danswiser commented 5 years ago

I removed $reader->next(); after running $reader->parseInnerTree() and it seems to have fixed the original problem. Now it just seems I'm running out of memory. I'll troubleshoot that separately.

Thank you.

evert commented 5 years ago

Awesome!