Doc #55184 [Com]: DOMDocument::load() throws an exception instead of returning false on error

From: Date: Tue, 13 Sep 2011 17:37:12 +0000
Subject: Doc #55184 [Com]: DOMDocument::load() throws an exception instead of returning false on error
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-7183@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=55184&edit=1 ID: 55184 Comment by: vaseem dot mca46 at gmail dot com Reported by: stuart at horuskol dot net Summary: DOMDocument::load() throws an exception instead of returning false on error Status: Bogus Type: Documentation Problem Package: Documentation problem PHP Version: Irrelevant Block user comment: N Private report: N New Comment: I used the below code and the file is in uploads folder. $doc = new DOMDocument(); $doc->load("uploads/p25661072.xml"); I got this warning below. Please let me know how to solve this. "Warning: DOMDocument::load() [domdocument.load]: I/O warning : failed to load external entity "file:///C:/Program%20Files/Apache%20Software%20Foundation/Apache2.2/htdocs/ConugamSMS/includes/uploads/p25661072.xml" in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\ConugamSMS\includes\surveytaking.php on line 74" Previous Comments: ------------------------------------------------------------------------ [2011-08-19 09:20:12] rquadling@php.net <?php $s_None = 'http://horuskol.net/media/php/map-not-xml.xml'; $s_Bad = 'http://horuskol.net/media/php/map-malformed-xml.xml'; $dom = new DOMDocument(); var_dump($dom->load('not-a-file')); var_dump($dom->load($s_None)); var_dump($dom->load($s_Bad)); ?> outputs ... Warning: DOMDocument::load(): I/O warning : failed to load external entity "file:///C:/Program%20Files/ImageMagick/not-a-file" in - on line 5 bool(false) Warning: DOMDocument::load(): Premature end of data in tag pre line 1 in http://horuskol.net/media/php/map-not-xml.xml, line: 6 in - on line 6 bool(false) Warning: DOMDocument::load(): Premature end of data in tag pre line 1 in http://horuskol.net/media/php/map-malformed-xml.xml, line: 6 in - on line 7 bool(false) As documented. Also, your code outputs ... Warning: DOMDocument::load(): I/O warning : failed to load external entity "file:///C:/Program%20Files/ImageMagick/not-a-file" in - on line 10 Error loading source file Warning: DOMDocument::load(): I/O warning : failed to load external entity "file:///C:/Program%20Files/ImageMagick/map-not-xml.xml" in - on line 18 Error loading source file Warning: DOMDocument::load(): I/O warning : failed to load external entity "file:///C:/Program%20Files/ImageMagick/map-malformed-xml.xml" in - on line 26 Error loading source file Which contains both the warning and the thrown exception. NFF. ------------------------------------------------------------------------ [2011-08-18 09:41:21] stuart at horuskol dot net Hi, If you look at my code you can see that I am catching the exceptions thrown by the call to DOMDocument::load and outputting the message in the exception. It is definitely not returning false. ------------------------------------------------------------------------ [2011-08-17 13:26:12] bjori@php.net Not enough information was provided for us to be able to handle this bug. Please re-read the instructions at http://bugs.php.net/how-to-report.php If you can provide more information, feel free to add it to this bug and change the status back to "Open". Thank you for your interest in PHP. I'm confused. You are saying it throws exceptions.. But your example clearly shows it doesn't throw exceptions, just prints warnings and returns false.. ------------------------------------------------------------------------ [2011-07-11 22:14:39] stuart at horuskol dot net Description: ------------ --- From manual page: http://www.php.net/domdocument.load%23Errors/Exceptions --- The manual page reports that this method returns false on failure - however, testing this function has resulted in exceptions being thrown instead. Can the manual be updated to reflect this? Test script: --------------- Example XML files: http://horuskol.net/media/php/map-not-xml.xml http://horuskol.net/media/php/map-malformed-xml.xml <?php $dom = new DOMDocument(); try { if (!$dom->load('not-a-file')) { throw new Exception('Error loading source file'); } } catch (Exception $e) { echo $e->getMessage(); } try { if (!$dom->load('map-not-xml.xml')) { throw new Exception('Error loading source file'); } } catch (Exception $e) { echo $e->getMessage(); } try { if (!$dom->load('map-malformed-xml.xml')) { throw new Exception('Error loading source file'); } } catch (Exception $e) { echo $e->getMessage(); } Expected result: ---------------- Error loading source file Error loading source file Error loading source file Actual result: -------------- DOMDocument::load(): I/O warning : failed to load external entity "not-a-file" DOMDocument::load(): Start tag expected, '<' not found in map-not-xml.xml, line: 1 DOMDocument::load(): Couldn't find end of Start Tag malformed line 2 in map-malformed-xml.xml, line: 2 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=55184&edit=1

« previous php.doc.bugs (#7183) next »