/** * Validates the current document against a RelaxNG schema, * optionally validates embedded Schematron rules too. * * \param string $source * Source of the RelaxNG schema to use for validation. * * \param bool $schematron * (optional) Whether embedded Schematron rules * should be validated too (\b true) or not (\b false). * The default is to also do $schematron validation. * * \retval bool * \b true if the document validates, * \b false otherwise. */ public function relaxNGValidateSource($source, $schematron = true) { $success = parent::relaxNGValidateSource($source); return $this->schematronValidation('string', $source, 'RNG', $success, $schematron); }
/** * Constructs a new ezcTreeXml object from the XML data in $xmlFile and using * the $store to retrieve data from. * * @param string $xmlFile * @param ezcTreeXmlDataStore $store */ public function __construct($xmlFile, ezcTreeXmlDataStore $store) { if (!file_exists($xmlFile)) { throw new ezcBaseFileNotFoundException($xmlFile, "XML"); } $previous = libxml_use_internal_errors(true); $dom = new DomDocument(); $dom->load($xmlFile); $dom->formatOutput = true; $errors = libxml_get_errors(); libxml_clear_errors(); if (count($errors)) { throw new ezcTreeInvalidXmlException($xmlFile, $errors); } $valid = $dom->relaxNGValidateSource(self::relaxNG); if (!$valid) { $errors = libxml_get_errors(); libxml_clear_errors(); throw new ezcTreeInvalidXmlFormatException($xmlFile, $errors); } libxml_use_internal_errors($previous); // Associate the DOM tree with the data store $store->setDomTree($dom); // Figure out the prefix - which is the "prefix" attribute on the root node. $document = $dom->documentElement; $prefix = $document->getAttribute('prefix'); // Figure out the last auto generated ID $autoId = false; $this->autoNodeId = $document->getAttribute('lastNodeId'); if ($this->autoNodeId !== "") { $autoId = true; } // Set member variables $this->dom = $dom; $this->xmlFile = $xmlFile; $this->properties['store'] = $store; $this->properties['prefix'] = $prefix; $this->properties['autoId'] = $autoId; }
private function relaxNGValidate(\DomDocument $dom, $ng) { try { $dom->relaxNGValidateSource($ng); $this->throwError(); } catch (\DOMException $e) { throw new \RuntimeException($e->getMessage()); } }