コード例 #1
0
 /**
  * Validates the xml definition using Relax NG.
  *
  * @param DomDocument $doc The document to validate
  *
  * @return boolean Whether the xml data is valid or not.
  * @throws Console_CommandLine_Exception
  * @todo use exceptions
  */
 public static function validate($doc)
 {
     if (is_dir('C:\\php\\pear\\data' . DIRECTORY_SEPARATOR . 'Console_CommandLine')) {
         $rngfile = 'C:\\php\\pear\\data' . DIRECTORY_SEPARATOR . 'Console_CommandLine' . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'xmlschema.rng';
     } else {
         $rngfile = dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'xmlschema.rng';
     }
     if (!is_readable($rngfile)) {
         Console_CommandLine::triggerError('invalid_xml_file', E_USER_ERROR, array('{$file}' => $rngfile));
     }
     return $doc->relaxNGValidate($rngfile);
 }
コード例 #2
0
ファイル: saveform.php プロジェクト: nithin8702/onlinescoring
}
if (empty($data)) {
    ajax_error('Cannot accept empty form data.');
}
$config = new \NRG\Configuration(CONFIG_FILE);
try {
    $rng = null;
    //Register a new error handler to handle libxml specific errors
    $originalHandler = set_error_handler("libxml_error_handler");
    //Create a new DomDocument object and load the XML data into it
    $xmldata = new DomDocument();
    $xmldata->loadXML($data, LIBXML_NOBLANKS | LIBXML_NOCDATA | LIBXML_NOENT);
    //Remove whitespaces from the data
    purifyXML($xmldata->documentElement);
    //Validate the data received
    $valid = $xmldata->relaxNGValidate(SCHEMA_DIR . $schemaName . SCHEMA_EXT);
    //Restore the original error handler
    set_error_handler($originalHandler);
    if ($valid === false) {
        ajax_error('Schema validation failed');
    }
    //Should not see this because of the error handler
    //Retrieve the database configuration
    $dbconf = $config->Database;
    //Make sure the username is registered with this application
    $db = new Database($dbconf['host'], $dbconf['user'], $dbconf['pass'], $dbconf['name'], $dbconf['port']);
    $session = $db->searchSession($session);
    if (empty($session)) {
        ajax_error('Could not find your session id in the database.');
    }
    $db->storeForm($schemaName, $session['id'], $xmldata->saveXML());
コード例 #3
0
 /**
  * Validates the xml definition using Relax NG.
  *
  * @param DomDocument $doc The document to validate
  *
  * @return boolean Whether the xml data is valid or not.
  * @throws Console_CommandLine_Exception
  * @todo use exceptions
  */
 public static function validate($doc)
 {
     $pkgRoot = __DIR__ . '/../../';
     $paths = array('@data_dir@/Console_CommandLine/data/xmlschema.rng', $pkgRoot . 'data/Console_CommandLine/data/xmlschema.rng', $pkgRoot . 'data/console_commandline/data/xmlschema.rng', $pkgRoot . 'data/xmlschema.rng', 'xmlschema.rng');
     foreach ($paths as $path) {
         if (is_readable($path)) {
             return $doc->relaxNGValidate($path);
         }
     }
     Console_CommandLine::triggerError('invalid_xml_file', E_USER_ERROR, array('{$file}' => $rngfile));
 }
コード例 #4
0
ファイル: DOM.php プロジェクト: erebot/dom
 /**
  * Validates the current document against a RelaxNG schema,
  * optionally validates embedded Schematron rules too.
  *
  * \param string $filename
  *      Path to the RelaxNG schema to use for validation.
  *
  * \param bool $schematron
  *      (optional) Whether embedded Schematron rules
  *      should be validated too (\b true) or not (\b false).
  *      The default is to also do $schematron validation.
  *
  * \retval bool
  *      \b true if the document validates,
  *      \b false otherwise.
  */
 public function relaxNGValidate($filename, $schematron = true)
 {
     $success = parent::relaxNGValidate($filename);
     return $this->schematronValidation('file', $filename, 'RNG', $success, $schematron);
 }
コード例 #5
0
ファイル: XmlParser.php プロジェクト: slrondon/MikrotikCenter
 /**
  * Validates the xml definition using Relax NG.
  *
  * @param DomDocument $doc The document to validate
  *
  * @return boolean Whether the xml data is valid or not.
  * @throws PEAR2\Console\CommandLine\Exception
  * @todo use exceptions only
  */
 public static function validate($doc)
 {
     $rngfile = __DIR__ . '/../../../../data/pear2.php.net/PEAR2_Console_CommandLine/xmlschema.rng';
     if (!is_file($rngfile)) {
         $rngfile = __DIR__ . '/../../../../data/xmlschema.rng';
     }
     if (!is_readable($rngfile)) {
         CommandLine::triggerError('invalid_xml_file', E_USER_ERROR, array('{$file}' => $rngfile));
     }
     return $doc->relaxNGValidate($rngfile);
 }
コード例 #6
0
 /**
  * Loads the XML API definition.
  *
  * @return void
  */
 protected function loadAPI()
 {
     // initialize xml mapping
     $p = is_dir('@data_dir@') ? array('@data_dir@', 'Services_Twitter', 'data') : array(dirname(__FILE__), '..', 'data');
     $d = implode(DIRECTORY_SEPARATOR, $p) . DIRECTORY_SEPARATOR;
     if ($this->getOption('validate') && class_exists('DomDocument')) {
         // this should be done only when testing
         $doc = new DomDocument();
         $doc->load($d . 'api.xml');
         $doc->relaxNGValidate($d . 'api.rng');
     }
     $xmlApi = simplexml_load_file($d . 'api.xml');
     foreach ($xmlApi->category as $category) {
         $catName = (string) $category['name'];
         $this->api[$catName] = array();
         foreach ($category->endpoint as $endpoint) {
             $this->api[$catName][(string) $endpoint['name']] = $endpoint;
         }
     }
 }
コード例 #7
0
 /**
  * Validates the xml definition using Relax NG.
  *
  * @param DomDocument $doc The document to validate
  *
  * @return boolean Whether the xml data is valid or not.
  * @throws Console_CommandLine_Exception
  * @todo use exceptions
  */
 public static function validate($doc) 
 {
     if (is_dir('/Users/nojima/Sites/workspace/twitter2mixi/extlibs/pear/data' . DIRECTORY_SEPARATOR . 'Console_CommandLine')) {
         $rngfile = '/Users/nojima/Sites/workspace/twitter2mixi/extlibs/pear/data' . DIRECTORY_SEPARATOR
             . 'Console_CommandLine' . DIRECTORY_SEPARATOR . 'data' 
             . DIRECTORY_SEPARATOR . 'xmlschema.rng';
     } else {
         $rngfile = dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' 
             . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'data'
             . DIRECTORY_SEPARATOR . 'xmlschema.rng';
     }
     if (!is_readable($rngfile)) {
         Console_CommandLine::triggerError('invalid_xml_file',
             E_USER_ERROR, array('{$file}' => $rngfile));
     }
     return $doc->relaxNGValidate($rngfile);
 }
コード例 #8
0
ファイル: DOM.php プロジェクト: oaki/demoshop
 /**
  * Static helper function to validate document against a schema
  * @param string
  * @param string
  * @param boolean
  */
 public static function validate($xml, $schema, $relax = false)
 {
     $doc = new \DomDocument();
     set_error_handler(function ($errNo, $errMsg) {
         restore_error_handler();
         $errMsg = preg_replace('#^.*error :#', '', $errMsg);
         throw new DOMException($errMsg);
     });
     $doc->loadXML($xml);
     $validation = $relax ? $doc->relaxNGValidate($schema) : $doc->schemaValidate($schema);
     restore_error_handler();
     return $validation;
 }