It's quite difficult to catch the XML error messages in PHP 5.0, if something fails during loading or validating (For a way of at least displaying them, see my wiki article Catching XML Error Messages With PHP 5.0). Now, with the soon-to-come release of PHP 5.1, Rob posted a patch for allowing a proper way to handle those errors. We are still discussing the exact API and it will most certainly differ from the above patch. But the general approach will stay the same and look
approx. like this:
$ret = $xml->load('file.xml');
if (!$ret) {
$errors = libxml_get_errors();
foreach ($errors as $error) {
/* handle the errors here */
}
libxml_clear_errors();
}
Watch this space or the php mailinglists for the final API and when it's actually committed in CVS.