PHP and Relax-NG validation

To validate an xml file with a Relax-NG schema in PHP, you can use the XMLReader library:

$xml_reader = new XMLReader();
$xml_reader->setRelaxNGSchema($relax_ng_file);
$xml_reader->XML($xml_input->asXML());
if (!$xml_reader->isValid()) throw new Exception('failed RelaxNG validation);

I did not find how to retrieve corresponding error.
If you need a more verbose relax-ng validator, you can use ‘xmllint‘ in linux command console (part of ‘libxml2’ package).

sources

Post a Comment

Your email is never published nor shared. You're allow to say what you want...