本文整理汇总了PHP中DomDocument::schemaValidate方法的典型用法代码示例。如果您正苦于以下问题:PHP DomDocument::schemaValidate方法的具体用法?PHP DomDocument::schemaValidate怎么用?PHP DomDocument::schemaValidate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DomDocument
的用法示例。
在下文中一共展示了DomDocument::schemaValidate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validate
function validate($xml, $schema)
{
$doc = new DomDocument();
$doc->Load($xml);
if (@$doc->schemaValidate($schema)) {
printf('%s is valid against %s' . "\n", $xml, $schema);
} else {
printf('!!! %s is not valid against %s' . "\n", $xml, $schema);
}
}
示例2: validate
public function validate($path_to_mods)
{
$mods = new \DomDocument('1.0');
$mods->load($path_to_mods);
if ($mods->schemaValidate($this->schema_location)) {
$this->log->addInfo("MODS file validates", array('file' => $path_to_mods));
} else {
$this->log->addWarning("MODS file does not validate", array('file' => $path_to_mods));
}
}
示例3: testExportDemo
public function testExportDemo()
{
$fname = "../../docs/export-demo.xml";
$version = WikiExporter::schemaVersion();
$dom = new DomDocument();
$dom->load($fname);
// Ensure, the demo is for the current version
$this->assertEquals($dom->documentElement->getAttribute('version'), $version, 'export-demo.xml should have the current version');
$this->assertTrue($dom->schemaValidate("../../docs/export-" . $version . ".xsd"), "schemaValidate has found an error");
}
示例4: validateXmlFileAgainstXsd
/**
* Validates a xml file against the xsd.
*
* The validation is slow, because php has to read the xsd on each call.
*
* @param $fname string: name of file to validate
*/
protected function validateXmlFileAgainstXsd($fname)
{
$version = WikiExporter::schemaVersion();
$dom = new DomDocument();
$dom->load($fname);
try {
$this->assertTrue($dom->schemaValidate("../../docs/export-" . $version . ".xsd"), "schemaValidate has found an error");
} catch (Exception $e) {
$this->fail("xml not valid against xsd: " . $e->getMessage());
}
}
示例5: validate_file
public function validate_file($file)
{
libxml_use_internal_errors(true);
$DOM = new DomDocument();
// $DOM->loadXML($xmlString);
$DOM->load($file);
if (!$DOM->schemaValidate(dirname(__FILE__) . '/xml/schema.xsd')) {
$this->errors = libxml_get_errors();
return false;
}
return true;
}
示例6: validateXmlFileAgainstXsd
/**
* Validates a xml file against the xsd.
*
* The validation is slow, because php has to read the xsd on each call.
*
* @param $fname string: name of file to validate
*/
protected function validateXmlFileAgainstXsd($fname)
{
$version = WikiExporter::schemaVersion();
$dom = new DomDocument();
$dom->load($fname);
// Ensure, the demo is for the current version
$this->assertEquals($dom->documentElement->getAttribute('version'), $version, 'export-demo.xml should have the current version');
try {
$this->assertTrue($dom->schemaValidate("../../docs/export-" . $version . ".xsd"), "schemaValidate has found an error");
} catch (Exception $e) {
$this->fail("xml not valid against xsd: " . $e->getMessage());
}
}
示例7: validate_xml
function validate_xml($xmlString)
{
libxml_use_internal_errors(true);
$dom = new DomDocument();
$dom->loadXML($xmlString);
$errors = true;
if (!@$dom->schemaValidate('')) {
$errors = libxml_get_errors();
if (0 == sizeof($errors)) {
$errors = true;
}
}
return $errors;
}
示例8: testDatabasePackageName
public function testDatabasePackageName()
{
$schema = <<<EOF
<database name="bookstore" package="my.sub-directory">
<table name="book">
<column name="id" required="true" primaryKey="true" autoIncrement="true" type="INTEGER" />
<column name="title" type="VARCHAR" size="100" primaryString="true" />
</table>
</database>
EOF;
$dom = new DomDocument('1.0', 'UTF-8');
$dom->loadXML($schema);
$this->assertTrue($dom->schemaValidate($this->xsdFile));
}
示例9: isValid
public static function isValid($data)
{
$doc = new DomDocument('1.0');
$doc->loadXML($data);
$errors = libxml_get_errors();
if ($errors) {
return false;
}
if (strpos($data, 'version="1.2">') !== false) {
$schema = __DIR__ . '/../data/xliff-core-1.2-transitional.xsd';
if (!$doc->schemaValidate($schema)) {
return false;
}
}
return true;
}
示例10: matches
public function matches($schemaFile)
{
foreach ($this->xml as $id => $dom) {
$configElement = $dom->getElementsByTagName('config');
if (1 !== $configElement->length) {
throw new \InvalidArgumentException(sprintf('Can only test a file if it contains 1 <config> element, %d given', $configElement->length));
}
$configDom = new \DomDocument();
$configDom->appendChild($configDom->importNode($configElement->item(0), true));
libxml_use_internal_errors(true);
if (!$configDom->schemaValidate($schemaFile)) {
$this->errors = libxml_get_errors();
$this->failingElement = $id;
return false;
}
}
return true;
}
示例11: validate
/**
* Short description of method validate
*
* @access public
* @author Bertrand Chevrier, <bertrand.chevrier@tudor.lu>
* @param string schema
* @return boolean
*/
public function validate($schema = '')
{
//You know sometimes you think you have enough time, but it is not always true ...
//(timeout in hudson with the generis-hard test suite)
helpers_TimeOutHelper::setTimeOutLimit(helpers_TimeOutHelper::MEDIUM);
$content = $this->getContent();
if (!empty($content)) {
try {
libxml_use_internal_errors(true);
$dom = new DomDocument();
$dom->formatOutput = true;
$dom->preserveWhiteSpace = false;
$this->valid = $dom->loadXML($content);
if ($this->valid && !empty($schema)) {
$this->valid = $dom->schemaValidate($schema);
}
if (!$this->valid) {
$this->addErrors(libxml_get_errors());
}
libxml_clear_errors();
} catch (DOMException $de) {
$this->addError($de);
}
}
helpers_TimeOutHelper::reset();
return (bool) $this->valid;
}
示例12: validateXML
public static function validateXML($xmlStr)
{
if (SIF_VALIDATE == 'Y' or SIF_VALIDATE == 'W') {
libxml_use_internal_errors(true);
$xml = explode("\n", $xmlStr);
$objDom = new DomDocument();
if ($xmlStr == '' || $xmlStr == null) {
ZitLog::writeToErrorLog('[Xml missing in request]', 'Xml is missing in request can not process message', 'Process Message', $_SESSION['ZONE_ID']);
echo '<FATAL_ERROR>XML FORMAT</FATAL_ERROR>';
exit;
}
if (!$objDom->loadXML($xmlStr)) {
ZitLog::writeToErrorLog('[Error loading xml to parse]', $xmlStr, 'Process Message', $_SESSION['ZONE_ID']);
echo '<FATAL_ERROR>XML FORMAT</FATAL_ERROR>';
exit;
}
$schema = $_SESSION['ZONE_VERSION_SCHEMA_DIR'];
if (!$objDom->schemaValidate($schema)) {
$errorString = '';
$allErrors = libxml_get_errors();
foreach ($allErrors as $error) {
$errorString .= SifProcessRequest::Display_xml_error($error, $xml);
}
ZitLog::writeToErrorLog("[Error Validating Xml]", "Request Xml:\n{$xmlStr} \n\nSchema Errors:{$errorString}", "Process Message", $_SESSION['ZONE_ID']);
if (SIF_VALIDATE == 'Y') {
return false;
} else {
return true;
}
} else {
return true;
}
} else {
return true;
}
}
示例13: add_xml_observations
function add_xml_observations()
{
global $baseURL, $entryMessage, $objSession, $mailTo, $mailFrom, $loggedUser, $objConstellation, $objObject, $objCatalog, $objLocation, $objInstrument, $objFilter, $objEyepiece, $objLens, $objDatabase, $objObserver, $objObservation;
if ($_FILES['xml']['tmp_name'] != "") {
$xmlfile = $_FILES['xml']['tmp_name'];
} else {
$entryMessage .= LangXMLError3;
$_GET['indexAction'] = "add_xml";
return;
}
// Make a DomDocument from the file.
$dom = new DomDocument();
$xmlfile = realpath($xmlfile);
// Load the xml document in the DOMDocument object
$dom->Load($xmlfile);
$searchNode = $dom->getElementsByTagName("observations");
$version = $searchNode->item(0)->getAttribute("version");
if ($version == "2.0" || $version == "2.1") {
} else {
$entryMessage .= LangXMLError1;
$_GET['indexAction'] = "add_xml";
return;
}
// Use the correct schema definition to check the xml file.
$xmlschema = str_replace(' ', '/', $searchNode->item(0)->getAttribute("xsi:schemaLocation"));
$xmlschema = $baseURL . "xml/oal21/oal21.xsd";
// Validate the XML file against the schema
if ($dom->schemaValidate($xmlschema)) {
// The XML file is valid. Let's start reading in the file.
// Only 2.0 and 2.1 files!
// Check the observers -> In OpenAstronomyLog 2.0 the deepskylog_id is also added
$searchNode = $dom->getElementsByTagName("observers");
$observer = $searchNode->item(0)->getElementsByTagName("observer");
$observerArray = array();
$id = "";
foreach ($observer as $observer) {
$tmpObserverArray = array();
// Get the id and the name of the observers in the comast file
$comastid = $observer->getAttribute("id");
$name = htmlentities($observer->getElementsByTagName("name")->item(0)->nodeValue, ENT_COMPAT, "UTF-8", 0);
$tmpObserverArray['name'] = $name;
$surname = htmlentities($observer->getElementsByTagName("surname")->item(0)->nodeValue, ENT_COMPAT, "UTF-8", 0);
$tmpObserverArray['surname'] = $surname;
if ($observer->getElementsByTagName("fstOffset")->item(0)) {
$fstOffset[$comastid] = $observer->getElementsByTagName("fstOffset")->item(0)->nodeValue;
} else {
$fstOffset[$comastid] = 0.0;
}
$observerid = $observer->getElementsByTagName("account");
$obsid = "";
foreach ($observerid as $observerid) {
if ($observerid->getAttribute("name") == "www.deepskylog.org") {
$obsid = $observerid->nodeValue;
}
}
// Get the name of the observer which is logged in in DeepskyLog
$deepskylog_username = $objObserver->getObserverProperty($_SESSION['deepskylog_id'], 'firstname') . " " . $objObserver->getObserverProperty($_SESSION['deepskylog_id'], 'name');
if ($obsid != "") {
if ($obsid == $_SESSION['deepskylog_id']) {
$id = $comastid;
}
} else {
if ($deepskylog_username == $name . " " . $surname) {
$id = $comastid;
}
}
$observerArray[$comastid] = $tmpObserverArray;
}
if ($id == "") {
$entryMessage .= LangXMLError2 . $deepskylog_username . LangXMLError2a;
$_GET['indexAction'] = "add_xml";
return;
} else {
$objObserver->setObserverProperty($_SESSION['deepskylog_id'], 'fstOffset', $fstOffset[$id]);
}
$targets = $dom->getElementsByTagName("targets");
$target = $targets->item(0)->getElementsByTagName("target");
$targetArray = array();
foreach ($target as $target) {
$targetInfoArray = array();
$targetid = $target->getAttribute("id");
$targetInfoArray["name"] = $target->getElementsByTagName("name")->item(0)->nodeValue;
$aliases = $target->getElementsByTagName("alias");
$aliasesArray = array();
$cnt = 0;
foreach ($aliases as $aliases) {
$aliasesArray["alias" . $cnt] = $aliases->nodeValue;
$cnt = $cnt + 1;
}
// Check if the datasource is defined. If this is the case, get it. Otherwise, set to OAL
if ($target->getElementsByTagName("datasource")->item(0)) {
$targetInfoArray["datasource"] = $target->getElementsByTagName("datasource")->item(0)->nodeValue;
} else {
$targetInfoArray["datasource"] = "OAL";
}
$valid = true;
// Get the type
if ($target->getAttribute("xsi:type")) {
$type = $target->getAttribute("xsi:type");
$next = 1;
//.........这里部分代码省略.........
示例14: DomDocument
<?php
// načtení dokumentu XML
$xml = new DomDocument();
$xml->load("objednavka.xml");
//validace za použití konkrétního souboru se XML schématem;
//pokud by schéma bylo v RelaxNG, je možné využít funkci $xml->relaxNGValidate(file)
//pokud bychom nechtěli schéma načítat ze souboru, ale měli jej jako řetězec, použijeme funkci $xml->schemaValidateSource(schemaStr)
$result = $xml->schemaValidate('objednavka.xsd');
if ($result) {
echo 'Dokument je validní.';
} else {
echo 'Dokument není validní';
}
示例15: testBuild
public function testBuild()
{
$this->if($adapter = new atoum\test\adapter())->and($adapter->extension_loaded = true)->and($adapter->get_class = $class = 'class')->and($runner = new atoum\runner())->and($score = new runner\score())->and($report = $this->newTestedInstance($adapter))->and($runner->setScore($score))->and($testScore = new atoum\test\score())->and($testScore->addPass())->and($test = new \mock\mageekguy\atoum\test())->and($test->getMockController()->getCurrentMethod[1] = $method = 'method')->and($test->getMockController()->getCurrentMethod[2] = $otherMethod = 'otherMethod')->and($test->getMockController()->getCurrentMethod[3] = $thirdMethod = 'thirdMethod')->and($test->setScore($testScore))->and($path = join(DIRECTORY_SEPARATOR, array(__DIR__, 'resources')))->and($testScore->addDuration('foo', $class, $method, $duration = 1))->and($testScore->addUncompletedMethod(uniqid(), $class, $otherMethod, $exitCode = 1, $output = 'output'))->and($testScore->addSkippedMethod(uniqid(), $class, $thirdMethod, $line = rand(1, PHP_INT_MAX), $message = 'message'))->and($report->handleEvent(atoum\test::afterTestMethod, $test))->and($testScore->addPass())->and($testScore->addPass())->and($report->handleEvent(atoum\test::afterTestMethod, $test))->and($report->handleEvent(atoum\test::afterTestMethod, $test))->and($score->merge($testScore))->and($report->handleEvent(atoum\runner::runStop, $runner))->then->castToString($report)->isEqualToContentsOfFile(join(DIRECTORY_SEPARATOR, array($path, '1.xml')))->object($dom = new \DomDocument())->boolean($dom->loadXML((string) $report))->isTrue()->boolean($dom->schemaValidate(join(DIRECTORY_SEPARATOR, array($path, 'xunit.xsd'))))->isTrue();
}