/** * @dataProvider provider */ public function testPageValid ($page, $user) { if (!empty ($user)) $this->login ($user); $this->dispatch ($page); $dom = new DomDocument; Logger::get_logger ()->debug ($this->getResponse()->getBody()); $dom->loadXML ($this->getResponse()->getBody(), LIBXML_DTDLOAD); $this->assertTrue ($dom->validate (), $this->getResponse()->getBody()); }
function validateXML($xmlFile) { $dom = new DomDocument(); $dom->load($xmlFile); if (@$dom->validate()) { echo $xmlFile . " valido<br/>"; } else { echo $xmlFile . " no valido<br/>"; } }
<body> <?php include 'stylearray.php'; //Denna rad inkluderar PHP-filen som styr layouten på sidan. //Rad 10-32 används till DTD-valideringen! function HandleXmlError($errno, $errstr, $errfile, $errline) { echo $errno . " " . $errstr . "<br>"; } $file = 'xdxf.xml'; $dom = new DomDocument(); $dom->preserveWhiteSpace = FALSE; set_error_handler('HandleXmlError'); $loadstate = $dom->load($file); if ($loadstate) { $validatestate = $dom->validate(); if ($validatestate) { echo "<div class='validate'>Validation of DTD successful!</div>"; } else { echo "<div class='validate'>Validation of DTD-test failed!</div><br/>"; } } else { echo "<div class='validate'>Well-formedness test Failed!</div><br/>"; } restore_error_handler(); //Rad 35-40 används för att skapa layoutalternativstaggar som skall kunna väljas mellan. echo "<div id='colors'>"; echo "Choose your preferred color-scheme: "; while (list($key, $val) = each($styleSheets)) { echo "<a href='styleswitcher.php?SETSTYLE=" . $key . "'>" . $val["name"] . "</a> "; }
/** * Validates the document against its DTD. * * \param bool $schematron * (optional) The value of this parameter is currently * unused as there is no way to embed Schematron rules * into a DTD. This parameter is provided only to make * the API uniform accross the different methods of this * class. * * \retval bool * \b true if the document validates, * \b false otherwise. * * \note * This method is the same as the regular DomDocument::validate() * method excepts that it captures errors so they can be later * retrieved with the ::Erebot::DOM::DOM::getErrors() method. * * \note * There is currently no way to embed Schematron rules * into a Document Type Declaration. Therefore, the * value of the $schematron parameter is always ignored. */ public function validate($schematron = false) { $success = parent::validate(); $quiet = !libxml_use_internal_errors(); if (!$quiet) { $this->errors = array_merge($this->errors, libxml_get_errors()); libxml_clear_errors(); } return $success; }
function parse_spec_error(&$info) { global $message, $errortype, $fix, $xml, $history; // This means that the page was redirected from upload_spec.php and // indicates that an error occurred during specialisation. We can thus // try and parse the xml error message and inform the user. $error = $_SESSION['specerror']; // first check that there is actually an error message containing XML if ($error != '' && preg_match('/\\n\\<\\<\\n(.*?)\\>\\>\\n/s', $error, $matches)) { global $backend_dir; $dom = new DomDocument(); $xml = "<?xml version='1.0' encoding='utf-8'?>\n" . "<!DOCTYPE error SYSTEM 'file://{$backend_dir}/error.dtd'>\n" . $matches[1]; $dom->loadXML($xml); set_error_handler("validate_error_handler"); if (!$dom->validate()) { ?> <html><head> <link type="text/css" rel="stylesheet" href="xmlverbatim.css"/> </head><body><p><?php global $validate_error; echo $validate_error; echo "</p>\n"; echo process_xml($xml, 'xmlverbatim.xsl'); echo "<p><b>XML does not validate!</b></p></body></html>"; exit; } restore_error_handler(); //echo process_xml($xml, 'xmlverbatim.xsl'); $xml = simplexml_load_string($xml); // should be the following but it doesn't work! //$xml = simplexml_import_dom($dom); $message = (string) $xml->message; $errortype = (string) $xml->type; $problem = (string) $xml->problem; $fix = false; $info = array(); if ($xml->xpath('programpoint')) { $pp = $xml->programpoint; $currentpred = (string) $pp->predicate; $currentpredarity = (string) $pp->predicate['arity']; $currentpredclause = (string) $pp->localclause; $annotation = (string) $pp->annotation; $path = '['; if ($xml->xpath('/error/programpoint/path')) { $path_xml = $xml->xpath('/error/programpoint/path/point'); for ($i = 0; $i < count($path_xml); ++$i) { $ann = (string) $path_xml[$i]; $arg = (string) $path_xml[$i]['arg']; if ($i > 0) { $path .= ', '; } $path .= "({$ann}, {$arg})"; } } $path .= ']'; $extra['ann'] = 'unsafe'; $extra['pred'] = $currentpred; $extra['arity'] = $currentpredarity; $extra['clause'] = $currentpredclause; $extra['path'] = $path; if ($xml->xpath('/error/programpoint/correctann')) { if ($xml->xpath('/error/programpoint/correctann/annotation')) { $extra['type'] = 'correctann'; $extra['fix'] = (string) $pp->correctann->annotation; $fix = true; } else { $extra['type'] = 'fix_hide_nf'; $fix = true; } } else { $extra['type'] = 'infoann'; } $info[] = $extra; } if ($xml->xpath('filter')) { $f = $xml->filter; $extra = array(); $extra['pred'] = (string) $f->predicate; $extra['arity'] = (string) $f->predicate['arity']; if ($xml->xpath('/error/filter/correctfilt')) { $make_dynamic = $xml->xpath('/error/filter/correctfilt/make_dynamic'); if ($make_dynamic) { if (count($info)) { $info[0]['type'] = 'correctann'; $info[0]['fix'] = (string) $xml->programpoint->annotation; } $extra['type'] = 'correctfilt'; for ($i = 0; $i < count($make_dynamic); ++$i) { $a = $extra; $a['make_dyn'] = (string) $make_dynamic[$i]; $info[] = $a; } $fix = true; } else { $extra['type'] = 'replacefilt'; $extra['newfilt'] = $xml->filter->correctfilt->replace_filt; $fix = true; $info[] = $extra; } } else { $extra['type'] = 'infofilt'; $info[] = $extra; } } if ($xml->xpath('history')) { $history = array(); $historyxml = $xml->xpath('/error/history/call'); for ($i = 0; $i < count($historyxml); ++$i) { $history[] = (string) $historyxml[$i]; } } return true; } return false; }
/** * Make sure response content HTML passes DTD validation * this doesn't seem to work with HTML 4.01 Trans. * * {{code: php * ... * $this->assertValid(); * ... * ?> * }} * * @param string $msg */ public function assertValid($msg = null) { $responseBody = $this->response->getBody(); $dom = new DomDocument(); $dom->loadHTML($responseBody); $this->assertTrue($dom->validate(), $msg); }