Note that there are some explanatory texts on larger screens.

plurals
  1. POloadXML unhandleable error
    text
    copied!<p>I'm using PEAR <a href="http://pear.php.net/package/XML_Feed_Parser" rel="nofollow">XML_Feed_Parser</a>. I have some <a href="http://feeds.feedburner.com/bishop-it/LaoT" rel="nofollow">bad xml</a> that I give to it and get error. </p> <pre><code>DOMDocument::loadXML(): Input is not proper UTF-8, indicate encoding ! Bytes: 0xE8 0xCF 0xD3 0xD4 in Entity, line: 7 </code></pre> <p><em>It's actually html in wrong encoding - KOI8-R.</em></p> <p>It's ok to get error but I can't handle it! </p> <p>When I create new XML_Feed_Parser instance with $feed = new XML_Feed_Parser($xml);</p> <p>it calls to __construct() that looks like that</p> <pre><code>$this-&gt;model = new DOMDocument; if (! $this-&gt;model-&gt;loadXML($feed)) { if (extension_loaded('tidy') &amp;&amp; $tidy) { /* tidy stuff */ } } else { throw new Exception('Invalid input: this is not valid XML'); } </code></pre> <p>Where we can see that if loadXML() failed then it throw exception.</p> <p>I want to catch error from loadXML() to skip bad XMLs and notify user. So i wrapped my code with try-catch like that</p> <pre><code>try { $feed = new XML_Feed_Parser($xml); /* ... */ } catch(Exception $e) { echo 'Feed invalid: '.$e-&gt;getMessage(); return False; } </code></pre> <p>But even after that I get that error</p> <pre><code>DOMDocument::loadXML(): Input is not proper UTF-8, indicate encoding ! Bytes: 0xE8 0xCF 0xD3 0xD4 in Entity, line: 7 </code></pre> <p>I've read about loadXML() and found that</p> <blockquote> <p>If an empty string is passed as the source, a warning will be generated. This warning is not generated by libxml and cannot be handled using libxml's error handling functions. </p> </blockquote> <p>But somehow instead of warning i get error that halts my application. I've written my error handler and I saw that this is really warning ($errno is 2).</p> <p>So i see 2 solutions:</p> <ol> <li><p>Revert warnings to warnings - do not treat them like errors. (Google doesn't help me here). After that handle False returned from loadXML. </p></li> <li><p>Somehow catch that error.</p></li> </ol> <p>Any help?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload