23 if (!defined(
'XML_PARSE_BIG_LINES')) {
24 define(
'XML_PARSE_BIG_LINES', 1 << 22);
41 class DOM extends \DomDocument
55 public function __construct($version = null, $encoding = null)
58 if ($version === null && $encoding === null) {
59 parent::__construct();
60 } elseif ($encoding === null) {
61 parent::__construct($version);
63 parent::__construct($version, $encoding);
85 $success = parent::relaxNGValidate($filename);
86 return $this->schematronValidation(
113 $success = parent::relaxNGValidateSource($source);
114 return $this->schematronValidation(
141 $success = parent::schemaValidate($filename);
142 return $this->schematronValidation(
169 $success = parent::schemaValidateSource($source);
170 return $this->schematronValidation(
222 $base = dirname(__DIR__) .
223 DIRECTORY_SEPARATOR .
'data' .
225 $xsl1 = $base .
'ExtractSchFrom' . $schemaSource .
'.xsl';
226 $skeleton = $base .
'iso_schematron_skeleton_for_xslt1.xsl';
231 $quiet = !libxml_use_internal_errors();
233 $this->errors = array_merge($this->errors, libxml_get_errors());
234 libxml_clear_errors();
236 if (!$success || !$schematron) {
240 $schema = new \DomDocument();
241 if ($source ===
'file') {
242 $success = $schema->load($data, XML_PARSE_BIG_LINES);
244 $success = $schema->loadXML($data, XML_PARSE_BIG_LINES);
248 $this->errors = array_merge($this->errors, libxml_get_errors());
249 libxml_clear_errors();
256 $extractor = new \DomDocument();
257 $success = $extractor->loadXML(file_get_contents($xsl1), XML_PARSE_BIG_LINES);
259 $this->errors = array_merge($this->errors, libxml_get_errors());
260 libxml_clear_errors();
268 $processor = new \XSLTProcessor();
269 $processor->importStylesheet($extractor);
270 $result = $processor->transformToDoc($schema);
271 if ($result ===
false) {
276 $validator = new \DomDocument();
277 $success = $validator->loadXML(file_get_contents($skeleton), XML_PARSE_BIG_LINES);
279 $this->errors = array_merge($this->errors, libxml_get_errors());
280 libxml_clear_errors();
288 $processor->importStylesheet($validator);
289 $result = $processor->transformToDoc($result);
290 if ($result ===
false) {
295 $processor = new \XSLTProcessor();
296 $processor->registerPHPFunctions(
'\\Erebot\\DOM::getNodeLineNo');
297 $processor->importStylesheet($result);
298 $result = $processor->transformToDoc($this);
299 if ($result ===
false) {
304 foreach ($result->documentElement->childNodes as $child) {
305 if ($child->nodeType !== XML_ELEMENT_NODE) {
309 if ($child->localName !==
'assertionFailure') {
320 $error = new \LibXMLError();
321 $error->level = LIBXML_ERR_ERROR;
324 $error->message =
'';
325 $error->file = $this->documentURI;
329 foreach ($child->childNodes as $subchild) {
330 if ($subchild->nodeType !== XML_ELEMENT_NODE) {
333 if ($subchild->localName ===
'description' && $error->message ===
'') {
334 $error->message = $subchild->textContent;
335 } elseif ($subchild->localName ===
'location' && $error->path ===
'') {
336 $error->path = $subchild->textContent;
337 } elseif ($subchild->localName ===
'line') {
338 $error->line = (int) $subchild->textContent;
341 $this->errors[] = $error;
372 $success = parent::validate();
373 $quiet = !libxml_use_internal_errors();
375 $this->errors = array_merge($this->errors, libxml_get_errors());
376 libxml_clear_errors();
389 return $this->errors;
397 $this->errors = array();
400 public static function getNodeLineNo(array $nodes)
402 if (count($nodes) !== 1 || !($nodes[0] instanceof \DOMNode )) {
403 throw new \Exception();
405 return $nodes[0]->getLineNo();
Base class for other (Erebot-related) exceptions.
schemaValidate($filename, $schematron=true)
schemaValidateSource($source, $schematron=true)
relaxNGValidate($filename, $schematron=true)
schematronValidation($source, $data, $schemaSource, $success, $schematron)
validate($schematron=false)
An extension of PHP's DomDocument class that implements Schematron validation on top of RelaxNG/XML S...
$errors
Stores the LibXMLError errors raised during validation.
relaxNGValidateSource($source, $schematron=true)
__construct($version=null, $encoding=null)