예제 #1
0
 /**
  * Check if an xml code satisfy the schema.
  *
  * @param string $xml The xml code to verify
  * @param string $filename The name of the file from which the xml code has been read from
  *
  * @return string[]|null Return null of all is ok, a list of errors otherwise
  */
 public static function checkString($xml, $filename = '')
 {
     $doc = Utilities::stringToDOMDocument($xml, $filename);
     $errors = null;
     $preUseInternalErrors = libxml_use_internal_errors(true);
     try {
         if (!$doc->schemaValidateSource(static::getSchema())) {
             $errors = Utilities::explainLibXmlErrors($filename);
         }
     } catch (Exception $x) {
         libxml_use_internal_errors($preUseInternalErrors);
         libxml_clear_errors();
         throw $x;
     }
     libxml_use_internal_errors($preUseInternalErrors);
     return $errors;
 }
예제 #2
0
 /**
  * Return the XSLT document that fixes a source xml file.
  *
  * @throws Exception Throws an Exception if the xsd file couldn't be read.
  *
  * @return DOMDocument
  */
 protected static function getXsltDOMDocument()
 {
     static $cache = null;
     $xsltFile = __DIR__ . '/doctrine-xml-0.5.xsl';
     if (!isset($cache)) {
         $s = is_file($xsltFile) && is_readable($xsltFile) ? @file_get_contents($xsltFile) : false;
         if ($s === false) {
             throw new Exception('Failed to load the xslt file ' . $xsltFile);
         }
         $cache = $s;
     }
     return Utilities::stringToDOMDocument($cache, $xsltFile);
 }