SimpleXMLReader icon indicating copy to clipboard operation
SimpleXMLReader copied to clipboard

How to continue parsing after exception

Open bolidesoft opened this issue 2 years ago • 1 comments

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!

bolidesoft avatar May 23 '23 16:05 bolidesoft

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

dkrnl avatar May 28 '23 11:05 dkrnl