dkrnl / SimpleXMLReader

Wrapped XMLReader class, for simple SAX-reading of huge xml.
112 stars 43 forks source link

How to continue parsing after exception #17

Open bolidesoft opened 1 year ago

bolidesoft commented 1 year ago

hi! I've got a strange issue with the parser. The same PHP function with the same XML file works fine in Windows, but throws an exception in CentOS. The exception is inside expandSimpleXml() and the exact error message is "XMLReader::expand(): /home/mybooklist/xml/-1.xml:1897: parser error : PCDATA invalid Char value 209". Cannot understand this at all, but as a workaround, I want to skip the problem node that causes that error and continue parsing, but it just exits. Here is the code of callback function:

    protected function callbackOffer($reader)
    {
        try {
            $element = $reader->expandSimpleXml(); // copy of the current node as a SimpleXMLElement object
        } catch (Exception $e) {
            echo 'Caught exception: ',  $e->getMessage(), "\n";
            return true;
        }

... parsing $element there

I thought returning true should continue parsing, but it is not. Is it possible to continue parsing after that exception? How?

Thanks!

dkrnl commented 1 year ago

Hi! Can you show exception stack trace and example xml file (attachment pls)?