LibXML supports DTD, Schema and RelaxNG validation, during parsing,
and post parsing.
- • boolean attribute DOMDocument->validateOnParse
- • boolean DOMDocument->validate(string filename)
- • boolean DOMDocument->schemaValidate(string filename)
- • boolean DOMDocument->relaxNGValidate(string filename)
Parse & Validate
<?php
$dom = new domDocument;
$dom->validateOnParse = true;
$dom->load('note-invalid.xml');
?>
Parse Then Validate
<?php
$dom = new domDocument;
$dom->load('note.xml');
if (!$dom->validate('note.dtd')) {
print "Document note.dtd is not valid\n";
} else {
print "Document note.dtd is valid\n";
}
?>