public function __construct($path_to_xml_file, $validate_xml = false) { $this->path_to_xml_file = $path_to_xml_file; if (!$this->path_to_xml_file) { $this->valid_xml = false; } else { $valid = $validate_xml ? SchemaValidator::validate($this->path_to_xml_file) : true; if ($valid === true) { $this->valid_xml = true; } else { $this->valid_xml = false; } } }
public function build() { if(strlen(trim($_GET['validate'])) > 0) { $this->_view = $_GET['validate']; } try { $validator = new SchemaValidator(); if($validator->validate($this->_output,(DOCROOT . $this->_view))) { $result = json_encode(array('result'=>'success', 'errors' => array())); } else { $result = json_encode(array('result'=>'failed', 'errors' => $validator->getErrors())); } } catch(Exception $e) { return "b"; } return $result; }
/** * Create a schema for a given string * * @param string $stringValue * @return array */ protected function generateStringSchema($stringValue) { $schema = ['type' => 'string']; $schemaValidator = new SchemaValidator(); $detectedFormat = null; $detectableFormats = ['uri', 'email', 'ip-address', 'class-name', 'interface-name']; foreach ($detectableFormats as $testFormat) { $testSchema = ['type' => 'string', 'format' => $testFormat]; $result = $schemaValidator->validate($stringValue, $testSchema); if ($result->hasErrors() === false) { $detectedFormat = $testFormat; } } if ($detectedFormat !== null) { $schema['format'] = $detectedFormat; } return $schema; }
public static function eol_schema_validate($uri) { if (!$uri) { return false; } $valid = SchemaValidator::validate($uri); if ($valid !== true) { return array(); } $errors = array(); $warnings = array(); $reader = new \XMLReader(); $reader->open($uri); $i = 0; while (@$reader->read()) { if ($reader->nodeType == \XMLReader::ELEMENT && $reader->name == "taxon") { $taxon_xml = $reader->readOuterXML(); $t = simplexml_load_string($taxon_xml, null, LIBXML_NOCDATA); $t_dc = $t->children("http://purl.org/dc/elements/1.1/"); $t_dwc = $t->children("http://rs.tdwg.org/dwc/dwcore/"); $identifier = Functions::import_decode($t_dc->identifier); $source_url = Functions::import_decode($t_dc->source); $scientific_name = Functions::import_decode($t_dwc->ScientificName); if (!$identifier) { $warnings[$scientific_name]["taxon without dc:identifier"] = true; } if (!$source_url) { $warnings[$scientific_name]["taxon without dc:source"] = true; } foreach ($t->dataObject as $d) { $d_dc = $d->children("http://purl.org/dc/elements/1.1/"); $identifier = Functions::import_decode($d_dc->identifier); /* Checking requirements*/ if (!$identifier) { $warnings[$scientific_name]["data object without dc:identifier"] = true; } } $xml->taxon[$i] = null; $i++; } } return array($errors, $warnings); }
public static function eol_schema_validate($uri) { if (!$uri) { return false; } $valid = SchemaValidator::validate($uri); if ($valid !== true) { return array(); } $errors = array(); $warnings = array(); $reader = new \XMLReader(); $reader->open($uri); $i = 0; while (@$reader->read()) { if ($reader->nodeType == \XMLReader::ELEMENT && $reader->name == "taxon") { $taxon_xml = $reader->readOuterXML(); $t = simplexml_load_string($taxon_xml, null, LIBXML_NOCDATA); $t_dc = $t->children("http://purl.org/dc/elements/1.1/"); $t_dwc = $t->children("http://rs.tdwg.org/dwc/dwcore/"); $identifier = Functions::import_decode($t_dc->identifier); $source_url = Functions::import_decode($t_dc->source); $scientific_name = Functions::import_decode($t_dwc->ScientificName); if (!$identifier) { $warnings[$scientific_name]["taxon without dc:identifier"] = true; } if (!$source_url) { $warnings[$scientific_name]["taxon without dc:source"] = true; } foreach ($t->dataObject as $d) { $d_dc = $d->children("http://purl.org/dc/elements/1.1/"); $identifier = Functions::import_decode($d_dc->identifier); $data_type = Functions::import_decode($d->dataType); $license = Functions::import_decode($d->license); $source_url = Functions::import_decode($d_dc->source); $description = Functions::import_decode($d_dc->description, 0, 0); $object_url = Functions::import_decode($d->mediaURL); $subjects = array(); foreach ($d->subject as $s) { $subjects[] = trim((string) $s); } /* Checking requirements*/ if (!$identifier) { $warnings[$scientific_name]["data object without dc:identifier"] = true; } if (!$license) { $warnings[$scientific_name]["data object without license"] = true; } //if text: must have description if ($data_type == "http://purl.org/dc/dcmitype/Text" && !$description) { $errors[$scientific_name]["text without dc:description"] = true; } //if text: must have subject if ($data_type == "http://purl.org/dc/dcmitype/Text" && !$subjects) { $errors[$scientific_name]["text without subject"] = true; } //if image, movie or sound: must have object_url if ($data_type != "http://purl.org/dc/dcmitype/Text" && !$object_url) { $errors[$scientific_name]["media without mediaURL"] = true; } } //unset($xml->taxon[$i]); $xml->taxon[$i] = null; $i++; //if($i%100==0 && DEBUG) debug("Parsed taxon $i"); //if(defined("DEBUG_PARSE_TAXON_LIMIT") && $i >= DEBUG_PARSE_TAXON_LIMIT) break; } } return array($errors, $warnings); }