This method throws E_NOTICE errors for any validation errors. If you'd rather store validation errors in an array for gracious handling, you can use the code below.
<?php
function staticerror($errno, $errstr, $errfile, $errline, $errcontext, $ret = false)
{
static $errs = array();
if ($ret === true) {
return $errs;
}
$tag = 'DOMDocument::validate(): ';
$errs[] = str_replace($tag, '', $errstr);
}
$dom = new DOMDocument;
$dom->load('somefile');
set_error_handler('staticerror');
$old = ini_set('html_errors', false);
$doc->validate();
ini_set('html_errors', $old);
restore_error_handler();
$errs = staticerror(null, null, null, null, null, true);
print_r($errs);
?>