<?php

// Enable user error handling
libxml_use_internal_errors(true);

function libxml_display_error($error)
{
    $return = "<br/>\n";
    switch ($error->level) {
        case LIBXML_ERR_WARNING:
            $return .= "<b>Warning $error->code</b>: ";
            break;
        case LIBXML_ERR_ERROR:
            $return .= "<b>Error $error->code</b>: ";
            break;
        case LIBXML_ERR_FATAL:
            $return .= "<b>Fatal Error $error->code</b>: ";
            break;
    }
    $return .= trim($error->message);
    if ($error->file) {
        //$return .=    " in <b>$error->file</b>";
    }
    //$return .= " on line <b>$error->line</b>\n";

    return $return;
}

function libxml_display_errors()
{
    $errors = libxml_get_errors();
    $str = "";
	foreach ($errors as $error) {
        $str .= libxml_display_error($error).'</br>';
    }
    //libxml_clear_errors();
	return $str;
}

function libxml_schema_validate($filexml,$filexsd)
{

$xml = new DOMDocument(); 
$xml->load($filexml); 

if (!$xml->schemaValidate($filexsd)) {
    //print '<b>DOMDocument::schemaValidate() Generated Errors!</b>';
    return libxml_display_errors();
}else{
	return false;
}

}

?>