|
|
DOMDocument->relaxNGValidateSource() (no version information, might be only in CVS) DOMDocument->relaxNGValidateSource() --
Performs relaxNG validation on the document
Описаниеclass DOMDocument { bool relaxNGValidateSource ( string source ) }
Performs relaxNG validation on the document
based on the given RNG source.
Список параметров
source
A string containing the RNG schema.
Возвращаемые значения
Возвращает TRUE в случае успешного завершения или FALSE в случае возникновения ошибки.
add a note
User Contributed Notes
DOMDocument->relaxNGValidateSource()
gem at rellim dot com
12-Oct-2004 04:47
Took me a while to get a working example. Here it is:
<?php
ini_set( 'track_errors', 1);
ini_set('error_reporting', E_ALL | E_STRICT);
$rng = <<<EOT
<?xml version="1.0" encoding="UTF-8"?>
<grammar ns="" xmlns="http://relaxng.org/ns/structure/1.0"
datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
<start>
<element name="apple">
<element name="pear">
<data type="NCName"/>
</element>
</element>
</start>
</grammar>
EOT;
$bad_xml =<<<EOT
<?xml version="1.0"?>
<apple>
<pear>Pear</pear>
<pear>Pear</pear>
</apple>
EOT;
$good_xml =<<<EOT
<?xml version="1.0"?>
<apple>
<pear>Pear</pear>
</apple>
EOT;
Function relaxNG ( $xml, $rng ) {
$dom_xml = new DomDocument;
$dom_xml->loadXML($xml);
if ( $dom_xml->relaxNGValidateSource ( $rng ) ) {
echo "Good\n";
} else {
echo $php_errormsg . "\n";
}
}
relaxNG ($good_xml, $rng);
relaxNG ($bad_xml, $rng);
?>
results:
Good
Did not expect element pear there
|