/** * This function test the validity of the xml file * * @param string $xmlToTest path to the xml to validate */ public function xmlIsValid($xmlToTest) { $xml = new \DOMDocument(); $xml->load($xmlToTest); libxml_use_internal_errors(true); if (!$xml->schemaValidate($this->localXsd)) { $this->errors = XmlCrawlerHelper::formatLibXmlErrors(libxml_get_errors()); libxml_clear_errors(); return false; } return true; }
/** * this method return source Xml as SimpleXml Object if it's possible, false if not. * It should be false if source xml is distant and unattainable, or xml is incorrectly formatted, * or not validate by xsd file (via an XmlCrawlerValidator) * * @return \SimpleXml source Xml as SimpleXml Object */ public function getSimpleXml() { if ($this->localXml === null && $this->distantXml !== null) { $this->getDistantXmlWithCurl(); } if ($this->localXml === null) { $this->errors['localXml'] = 'localXml is null'; return false; } if ($this->validator !== null && !$this->validator->xmlIsValid($this->localXml)) { $this->errors['xmlNotValide'] = $this->validator->getErrors(); return false; } libxml_use_internal_errors(true); if (!($this->simpleXml = simplexml_load_file($this->localXml))) { $this->errors['badFormat'] = XmlCrawlerHelper::formatLibXmlErrors(libxml_get_errors()); libxml_clear_errors(); return false; } //@todo use XmlCrawlerArchiver if it's set. return $this->simpleXml; }