I have this code to validate an XML file against an XSD file:
$file = 'test.xml';
$schema = 'test.xsd';
$dom = new DOMDocument;
$dom->load($file);
if ($dom->schemaValidate($schema)) {
print "$file is valid.\n";
} else {
print "$file is invalid.\n";
}
If the xml file is invalid, then it says that it is invalid. The reason it is invalid (e.g. price is not an integer), however, is only given in a PHP warning, which I have to suppress so that user doesn't see it (with error_reporting(0)).
How can I get the text of that message and pass it on to the user, as I would do in C# with a try/catch?