note 69295 added to function.dom-domdocument-loadxml

From: Date: Wed, 30 Aug 2006 14:34:39 +0000
Subject: note 69295 added to function.dom-domdocument-loadxml
Groups: php.notes 
Request: Send a blank email to php-notes+get-116508@lists.php.net to get a copy of this message
loadXml reports an error instead of throwing an exception when the xml is not well formed. This is annoying if you are trying to to loadXml() in a try...catch statement. Apparently its a feature, not a bug, because this conforms to a spefication. If you want to catch an exception instead of generating a report, you could do something like <?php function HandleXmlError($errno, $errstr, $errfile, $errline) { if ($errno==E_WARNING && (substr_count($errstr,"DOMDocument::loadXML()")>0)) { throw new DOMException($errstr); } else return false; } function XmlLoader($strXml) { set_error_handler('HandleXmlError'); $dom = new DOMDocument(); $dom->loadXml($strXml); restore_error_handler(); return $dom; } ?> Returning false in function HandleXmlError() causes a fallback to the default error handler. ---- Server IP: 194.246.101.61 Probable Submitter: 83.145.93.242 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.dom-domdocument-loadxml.php Edit -- https://master.php.net/note/edit/69295 Del: integrated -- https://master.php.net/note/delete/69295/integrated Del: useless -- https://master.php.net/note/delete/69295/useless Del: bad code -- https://master.php.net/note/delete/69295/bad+code Del: spam -- https://master.php.net/note/delete/69295/spam Del: non-english -- https://master.php.net/note/delete/69295/non-english Del: in docs -- https://master.php.net/note/delete/69295/in+docs Del: other reasons-- https://master.php.net/note/delete/69295 Reject -- https://master.php.net/note/reject/69295 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#116508) next »