当前位置: 首页>>代码示例>>PHP>>正文


PHP XMLReader::isValid方法代码示例

本文整理汇总了PHP中XMLReader::isValid方法的典型用法代码示例。如果您正苦于以下问题:PHP XMLReader::isValid方法的具体用法?PHP XMLReader::isValid怎么用?PHP XMLReader::isValid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在XMLReader的用法示例。


在下文中一共展示了XMLReader::isValid方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: initialize

 /**
  * Reads the configuration file and creates the class attributes
  *
  */
 protected function initialize()
 {
     $reader = new XMLReader();
     $reader->open(parent::getConfigFilePath());
     $reader->setRelaxNGSchemaSource(self::WURFL_CONF_SCHEMA);
     libxml_use_internal_errors(TRUE);
     while ($reader->read()) {
         if (!$reader->isValid()) {
             throw new Exception(libxml_get_last_error()->message);
         }
         $name = $reader->name;
         switch ($reader->nodeType) {
             case XMLReader::ELEMENT:
                 $this->_handleStartElement($name);
                 break;
             case XMLReader::TEXT:
                 $this->_handleTextElement($reader->value);
                 break;
             case XMLReader::END_ELEMENT:
                 $this->_handleEndElement($name);
                 break;
         }
     }
     $reader->close();
     if (isset($this->cache["dir"])) {
         $this->logDir = $this->cache["dir"];
     }
 }
开发者ID:eusholli,项目名称:drupal,代码行数:32,代码来源:XmlConfig.php

示例2: isXml

function isXml($filename)
{
    $xml = new XMLReader();
    $xml->open($filename);
    $xml->setParserProperty(XMLReader::VALIDATE, true);
    return $xml->isValid();
}
开发者ID:eustasy,项目名称:normal-checks,代码行数:7,代码来源:xml.php

示例3: parse

 /**
  * Creates a Map of devices from the xml file
  *
  * @param string $fileName path to the xml file to parse
  * @return Map of <deviceId ModelDevice>
  */
 public static function parse($fileName, $validationSchema)
 {
     $devicesMap = array();
     $deviceID = null;
     $groupID = null;
     $reader = new XMLReader();
     $reader->open($fileName);
     $fullFileName = dirname(__FILE__) . DIRECTORY_SEPARATOR . $validationSchema;
     $reader->setRelaxNGSchema($fullFileName);
     libxml_use_internal_errors(TRUE);
     while ($reader->read()) {
         if (!$reader->isValid()) {
             throw new Exception(libxml_get_last_error()->message);
         }
         $nodeName = $reader->name;
         switch ($reader->nodeType) {
             case XMLReader::ELEMENT:
                 switch ($nodeName) {
                     case WURFL_Xml_Interface::DEVICE:
                         $groupIDCapabilitiesMap = array();
                         $deviceID = $reader->getAttribute(WURFL_Xml_Interface::ID);
                         $userAgent = $reader->getAttribute(WURFL_Xml_Interface::USER_AGENT);
                         $fallBack = $reader->getAttribute(WURFL_Xml_Interface::FALL_BACK);
                         $actualDeviceRoot = $reader->getAttribute(WURFL_Xml_Interface::ACTUAL_DEVICE_ROOT);
                         $currentCapabilityNameValue = array();
                         if ($reader->isEmptyElement) {
                             $device = new WURFL_Xml_ModelDevice($deviceID, $userAgent, $fallBack, $actualDeviceRoot);
                             $devicesMap[$deviceID] = $device;
                         }
                         break;
                     case WURFL_Xml_Interface::GROUP:
                         $groupID = $reader->getAttribute(WURFL_Xml_Interface::GROUP_ID);
                         $groupIDCapabilitiesMap[$groupID] = array();
                         break;
                     case WURFL_Xml_Interface::CAPABILITY:
                         $capabilityName = $reader->getAttribute(WURFL_Xml_Interface::CAPABILITY_NAME);
                         $capabilityValue = $reader->getAttribute(WURFL_Xml_Interface::CAPABILITY_VALUE);
                         $currentCapabilityNameValue[$capabilityName] = $capabilityValue;
                         $groupIDCapabilitiesMap[$groupID][$capabilityName] = $capabilityValue;
                         break;
                 }
                 break;
             case XMLReader::END_ELEMENT:
                 if ($nodeName == WURFL_Xml_Interface::DEVICE) {
                     $device = new WURFL_Xml_ModelDevice($deviceID, $userAgent, $fallBack, $actualDeviceRoot, $groupIDCapabilitiesMap);
                     $devicesMap[$device->id] = $device;
                 }
                 break;
         }
     }
     // end of while
     $reader->close();
     return $devicesMap;
 }
开发者ID:eusholli,项目名称:drupal,代码行数:60,代码来源:ParserUtil.php

示例4: testViewRss

 /**
  * testViewRss
  *
  */
 public function testViewRss()
 {
     // Disable debug mode to avoid DebugKit interruption
     $debug = Configure::read('debug');
     Configure::write('debug', 0);
     $this->testAction('/categories/view/1.rss', array('method' => 'GET', 'return' => 'contents'));
     // Restore debug setting
     Configure::write('debug', $debug);
     $expected_strings = array('Books', 'TestSlide1', 'TestSlide2');
     foreach ($expected_strings as $str) {
         $this->assertRegExp("/" . preg_quote($str) . "/", $this->contents);
     }
     $z = new XMLReader();
     $z->xml($this->contents, NULL, LIBXML_DTDVALID);
     $this->assertTrue($z->isValid());
 }
开发者ID:nicefirework,项目名称:open-slideshare,代码行数:20,代码来源:CategoriesControllerTest.php

示例5: __construct

 public function __construct(XMLReader $reader, $validate)
 {
     $skipNodes = array(XMLReader::SIGNIFICANT_WHITESPACE);
     do {
         if (!$reader->read()) {
             throw new InvalidArgumentException('Unexpected end of document');
         }
         if ($validate && !$reader->isValid()) {
             throw new InvalidArgumentException('Invalid document');
         }
     } while (in_array($reader->nodeType, $skipNodes));
     $fields = array('name', 'nodeType', 'value', 'isEmptyElement');
     $this->_properties = array();
     foreach ($fields as $field) {
         $this->_properties[$field] = $reader->{$field};
     }
 }
开发者ID:inscriptionweb,项目名称:PhotoShow,代码行数:17,代码来源:Node.php

示例6: _getXmlNode

 /**
  * Process a node from the XML Map
  * It is permitted for the XML to just define one or more tables without fields (when the 'use headers' option is used)
  *
  * Note: Calls itself recursively to process a tree
  *
  * @return bool returns true if all fine else false
  */
 private function _getXmlNode($node_content, $current_record, $xml_path)
 {
     $jinput = JFactory::getApplication()->input;
     $csvilog = $jinput->get('csvilog', null, null);
     $current_node = '';
     $xml_schema = new XMLReader();
     /**
      * Add a wrapper to make the XML viable and ensure that self closing tags contain a space before the '/>'
      * The XML may still be invalid but that's down to what the user entered
      */
     $node_content = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<da_root>" . $node_content . '</da_root>';
     $xml_schema->XML($node_content);
     // XML file to table map is valid XML - construct the arrays used in file extraction
     $use_read = true;
     // The XML could only be validated against a DTD if the syntax of the XML used for the map is made more complex
     $validate_xml = false;
     if ($validate_xml == true) {
         // Note: When the DTD is external, the property value must be set before the first read()
         $xml_schema->setParserProperty(XMLReader::VALIDATE, true);
     }
     while ($use_read ? $xml_schema->read() : $xml_schema->next()) {
         // Validation checking disabled because a DTD (or RELAX NG) schema is required.
         if ($validate_xml == true) {
             if ($xml_schema->isValid() == false) {
                 $xml_schema->close();
                 return false;
             }
         }
         // Default to a reading a single node in the next loop
         $use_read = true;
         // Ignore any node associated with the root
         if ($xml_schema->name == 'da_root') {
             continue;
         }
         // Process start elements
         if ($xml_schema->nodeType == XMLReader::ELEMENT) {
             $self_closing = $xml_schema->isEmptyElement;
             // Ready to add a new node - but only if the last node was closed
             if (!empty($current_node)) {
                 $csvilog->AddStats('incorrect', JText::sprintf('COM_CSVI_XML_NODE_UNCLOSED', $current_node));
                 return false;
             }
             // A new node was found - Check whether this is a new record type
             if (empty($current_record)) {
                 // New record type
                 // Check for a self-closing node
                 $self_closing = $xml_schema->isEmptyElement;
                 $current_record = strtolower($xml_schema->name);
                 $this->_xml_records[] = strtolower($current_record);
                 // Store any attributes
                 while ($xml_schema->moveToNextAttribute()) {
                     // Note1: $xml_schema->hasValue only indicates whether the element can have a value, not whether it does
                     // Note2: empty($xml_schema->value) always return true, regardless of the actual value
                     $value = $xml_schema->value;
                     if (!empty($value)) {
                         if ($this->_isXmlFieldNameValid($xml_schema->value)) {
                             $this->_xml_schema[$current_record]['attrs'][strtolower($xml_schema->name)] = trim($xml_schema->value);
                         } else {
                             $csvilog->AddStats('incorrect', JText::sprintf('COM_CSVI_XML_FILE_MAP_NO_REFERENCE', $xml_schema->value));
                             $xml_schema->close();
                             return false;
                         }
                     }
                 }
                 // Check for a self-closing node
                 if ($self_closing == true) {
                     $current_record = '';
                 }
             } else {
                 // New field type
                 $current_node = strtolower($xml_schema->name);
                 $current_path = $this->_getXmlNodePath($xml_path, $current_node);
                 // Store any attributes
                 while ($xml_schema->moveToNextAttribute()) {
                     // Note1: $xml_schema->hasValue only indicates whether the element can have a value, not whether it does
                     // Note2: empty($xml_schema->value) always return true, regardless of the actual value
                     $value = $xml_schema->value;
                     if (!empty($value)) {
                         if ($this->_isXmlFieldNameValid($xml_schema->value)) {
                             $this->_xml_schema[$current_record]['nodes'][$current_path]['attrs'][strtolower($xml_schema->name)] = trim($xml_schema->value);
                         } else {
                             $csvilog->AddStats('incorrect', JText::_('COM_CSVI_XML_FILE_MAP_NO_REFERENCE', $xml_schema->value));
                             $xml_schema->close();
                             return false;
                         }
                     }
                 }
                 $sub_node_content = $xml_schema->readInnerXML();
                 // Check whether there are any lower level nodes
                 if (strstr($sub_node_content, '<') === false) {
                     /**
                      * Content has no embedded nodes - Assume a field name
//.........这里部分代码省略.........
开发者ID:spiridonov-oa,项目名称:SheinCandles,代码行数:101,代码来源:xml.php

示例7: fn_exim_1c_get_external_file

function fn_exim_1c_get_external_file($filename)
{
    list($dir_1c, $dir_1c_url, $dir_1c_images) = fn_rus_exim_1c_get_dir_1c();
    if (!is_dir($dir_1c)) {
        fn_mkdir($dir_1c);
    }
    $file_path = $dir_1c . $filename;
    if (Registry::get('addons.rus_exim_1c.exim_1c_schema_version') == '2.07') {
        if (file_exists($file_path) && extension_loaded('XMLReader')) {
            $xml = new XMLReader();
            $xml->open($file_path);
            $xml->setParserProperty(XMLReader::VALIDATE, true);
            if (!$xml->isValid()) {
                @unlink($file_path);
            }
        }
    }
    if (fn_exim_1c_file_is_image($filename)) {
        if (!is_dir($dir_1c_images)) {
            fn_mkdir($dir_1c_images);
        }
        $file_path = $dir_1c_images . $filename;
    }
    $file = @fopen($file_path, 'w');
    if (!$file) {
        return false;
    }
    fwrite($file, fn_get_contents('php://input'));
    fclose($file);
    return true;
}
开发者ID:askzap,项目名称:ask-zap,代码行数:31,代码来源:func.php

示例8: while

    while ($reader->read()) {
    }
}
if ($reader->isValid()) {
    print "file relaxNG: ok\n";
} else {
    print "file relaxNG: failed\n";
}
$reader->close();
unlink($file);
$reader = new XMLReader();
$reader->XML($xmlstring);
if ($reader->setRelaxNGSchema($relaxngfile)) {
    while ($reader->read()) {
    }
}
if ($reader->isValid()) {
    print "string relaxNG: ok\n";
} else {
    print "string relaxNG: failed\n";
}
$reader->close();
$reader = new XMLReader();
$reader->XML($xmlstring);
if ($reader->setRelaxNGSchema('')) {
    echo 'failed';
}
$reader->close();
?>
===DONE===
开发者ID:badlamer,项目名称:hhvm,代码行数:30,代码来源:007.php

示例9: XMLReader

<?php

$reader = new XMLReader();
/* load xml document as a string */
$reader->XML(file_get_contents(dirname(__FILE__) . '/thedata.xml'));
/* tell the parser to perform syntax validation */
$reader->setParserProperty(XMLREADER_VALIDATE, TRUE);
// loop until end of document
// @ blocks the parser errors (missing DTD in this case)
while (@$reader->read()) {
}
echo "XML document is: " . ($reader->isValid() ? '' : ' not') . " valid.";
开发者ID:SandyS1,项目名称:presentations,代码行数:12,代码来源:xmlread_valid1.php

示例10: mkdir

if ($is_allowedToEdit && !empty($choice) && $choice == 'exportqti2') {
    require_once api_get_path(SYS_CODE_PATH) . 'exercice/export/qti2/qti2_export.php';
    $export = export_exercise_to_qti($exerciseId, true);
    $archive_path = api_get_path(SYS_ARCHIVE_PATH);
    $temp_dir_short = api_get_unique_id();
    $temp_zip_dir = $archive_path . $temp_dir_short;
    if (!is_dir($temp_zip_dir)) {
        mkdir($temp_zip_dir, api_get_permissions_for_new_directories());
    }
    $temp_zip_file = $temp_zip_dir . "/" . api_get_unique_id() . ".zip";
    $temp_xml_file = $temp_zip_dir . "/qti2export_" . $exerciseId . '.xml';
    file_put_contents($temp_xml_file, $export);
    $xmlReader = new XMLReader();
    $xmlReader->open($temp_xml_file);
    $xmlReader->setParserProperty(XMLReader::VALIDATE, true);
    $isValid = $xmlReader->isValid();
    if ($isValid) {
        $zip_folder = new PclZip($temp_zip_file);
        $zip_folder->add($temp_xml_file, PCLZIP_OPT_REMOVE_ALL_PATH);
        $name = 'qti2_export_' . $exerciseId . '.zip';
        DocumentManager::file_send_for_download($temp_zip_file, true, $name);
        unlink($temp_zip_file);
        unlink($temp_xml_file);
        rmdir($temp_zip_dir);
        exit;
        //otherwise following clicks may become buggy
    } else {
        $errorXmlExport = Display::return_message(get_lang('ErrorWritingXMLFile'), 'error');
    }
}
if ($origin != 'learnpath') {
开发者ID:secuencia24,项目名称:chamilo-lms,代码行数:31,代码来源:exercise.php

示例11: validateFile

 private function validateFile($file_name)
 {
     $extension = pathinfo($file_name, PATHINFO_EXTENSION);
     $file_info = explode(".", $file_name);
     $file_info1 = explode("_", $file_info[0]);
     $file_id = $file_info1[1];
     // verificam validitatea fisierului in fctie de extensie
     if ($extension == "xml") {
         $reader = new XMLReader();
         $reader->open(DIR_FILE_FOR_MATCHING . $file_name);
         // Set parser options - you must set this in order to use isValid method
         $reader->setParserProperty(XMLReader::VALIDATE, TRUE);
         $a = 0;
         if (!$reader->isValid()) {
             // se sterge din baza de date si de pe server
             $this->model_account_customer_file_for_matching->deleteFile($file_id);
             $this->session->data['warning'] = $this->language->get('text_xml_file_is_not_valid');
             return false;
         } else {
             // in cazul in care xml-ul este valid, verificam daca contine datele obligatorii specificate webservice-ului
             $xml = simplexml_load_file(DIR_FILE_FOR_MATCHING . $file_name);
             foreach ($xml->children()->children() as $child) {
                 $this->xml_node[] = strtoupper(trim($child->getName()));
             }
             $xml_valid = 1;
             foreach ($this->mandatory_data as $value) {
                 if (!in_array($value, $this->xml_node)) {
                     $xml_valid = 0;
                     break;
                 }
             }
             if ($xml_valid == 0) {
                 // se sterge din baza de date si de pe server
                 $this->model_account_customer_file_for_matching->deleteFile($file_id);
                 $this->session->data['warning'] = $this->language->get('text_xml_file_not_contain_mandatory_data');
                 return false;
             } else {
                 return true;
             }
         }
     } else {
         if ($extension == "csv") {
             $csv_delimiter = $this->model_account_customer_file_for_matching->getCsvDelimiter($file_id);
             $filerow = array();
             $filerow = @file(DIR_FILE_FOR_MATCHING . $file_name);
             $csv_header = explode($csv_delimiter, $filerow[0]);
             $csv_have_header = 1;
             // verificam daca fisierul csv are header
             foreach ($csv_header as $value) {
                 if (is_numeric(trim($value))) {
                     // se sterge din baza de date si de pe server
                     $this->model_account_customer_file_for_matching->deleteFile($file_id);
                     $this->session->data['warning'] = $this->language->get('text_csv_file_without_header');
                     return false;
                 }
             }
             // transformam in litere mari
             $header = array();
             foreach ($csv_header as $value) {
                 $header[] = strtoupper(trim($value));
             }
             // in cazul in care csv -ul are header, verificam daca headerul contine datele obligatorii specificate webservice-ului
             foreach ($this->mandatory_data as $value) {
                 if (!in_array($value, $header)) {
                     $csv_have_header = 0;
                     break;
                 }
             }
             if ($csv_have_header == 0) {
                 // se sterge din baza de date si de pe server
                 $this->model_account_customer_file_for_matching->deleteFile($file_id);
                 $this->session->data['warning'] = $this->language->get('text_csv_file_not_contain_mandatory_data');
                 return false;
             } else {
                 return true;
             }
         }
     }
 }
开发者ID:bgabor,项目名称:RenaniaOpencart,代码行数:79,代码来源:matchclientdata.php

示例12: XMLReader

<?php

$indent = 5;
/* Number of spaces to indent per level */
$xml = new XMLReader();
$xml->open("dtdexample.xml");
$xml->setParserProperty(XMLREADER::LOADDTD, TRUE);
$xml->setParserProperty(XMLREADER::VALIDATE, TRUE);
while ($xml->read()) {
    /* Print node name indenting it based on depth and $indent var */
    print str_repeat(" ", $xml->depth * $indent) . $xml->name . "\n";
    if ($xml->hasAttributes) {
        $attCount = $xml->attributeCount;
        print str_repeat(" ", $xml->depth * $indent) . " Number of Attributes: " . $xml->attributeCount . "\n";
    }
}
print "\n\nValid:\n";
var_dump($xml->isValid());
开发者ID:cefalo19,项目名称:php-src,代码行数:18,代码来源:xmlreader_validatedtd.php

示例13: __construct

 /**
  * Create a new XML node.
  *
  * \param XMLReader $reader
  *      XML reader object that will be used to create
  *      this node.
  *
  * \param bool $validate
  *      Whether an exception should be raised (\c true)
  *      or not (\c false) if the current node is not valid.
  *
  * \param bool $subtrees
  *      Whether to explore subtrees (\c true) or not (\c false).
  */
 public function __construct(\XMLReader $reader, $validate, $subtrees)
 {
     do {
         // We must silence read()/next() as old PHPs (5.3.x) emit warnings
         // which get caught by PHPUnit and other custom error handlers
         // when the methods fail and this is known to cause some issues.
         if ($subtrees && !@$reader->read() || !$subtrees && !@$reader->next()) {
             $error = libxml_get_last_error();
             // We reached the end of the document.
             // This is not an error per-se,
             // but it causes read() to fail anyway.
             // We throw a special error which gets caught
             // and dealt with appropriately by the caller.
             if ($error === false) {
                 throw new \InvalidArgumentException('End of document');
             }
             switch ($error->code) {
                 case self::XML_ERR_UNKNOWN_ENCODING:
                 case self::XML_ERR_UNSUPPORTED_ENCODING:
                     throw new \fpoirotte\XRL\Faults\UnsupportedEncodingException();
                     // Internal & memory errors are too hard to recreate
                     // and are thus excluded from code coverage analysis.
                     // @codeCoverageIgnoreStart
                 // Internal & memory errors are too hard to recreate
                 // and are thus excluded from code coverage analysis.
                 // @codeCoverageIgnoreStart
                 case self::XML_ERR_INTERNAL_ERROR:
                 case self::XML_ERR_NO_MEMORY:
                     throw new \fpoirotte\XRL\Faults\InternalErrorException();
                     // @codeCoverageIgnoreEnd
                 // @codeCoverageIgnoreEnd
                 case self::XML_ERR_INVALID_CHAR:
                     throw new \fpoirotte\XRL\Faults\InvalidCharacterException();
                     // Generic error handling.
                 // Generic error handling.
                 default:
                     throw new \fpoirotte\XRL\Faults\NotWellFormedException();
             }
         }
         if ($validate && !$reader->isValid()) {
             throw new \fpoirotte\XRL\Faults\InvalidXmlRpcException();
         }
         $subtrees = true;
     } while ($reader->nodeType === \XMLReader::SIGNIFICANT_WHITESPACE);
     $fields = array('isEmptyElement', 'localName', 'namespaceURI', 'nodeType', 'value');
     $this->properties = array();
     foreach ($fields as $field) {
         $this->properties[$field] = $reader->{$field};
     }
     $name = $reader->localName;
     if ($reader->namespaceURI !== '') {
         $name = '{' . $reader->namespaceURI . '}' . $name;
     }
     $this->properties['name'] = $name;
 }
开发者ID:fpoirotte,项目名称:xrl,代码行数:69,代码来源:Node.php

示例14: validateString

 /**
  * validates the xml string
  *
  * @return boolean true if the xml string is valid
  * @access private
  */
 private function validateString($xml_feed_string)
 {
     $reader = new XMLReader();
     $reader->XML($xml_feed_string);
     if ($reader->setRelaxNGSchema(RELAX_NG_IMPORT_SCHEMA)) {
         while ($reader->read()) {
         }
     }
     if (!$reader->isValid()) {
         return false;
     }
     $reader->close();
     return true;
 }
开发者ID:BackupTheBerlios,项目名称:medialib-svn,代码行数:20,代码来源:HgkMediaLib_MetaDataFeed.php

示例15: XMLReader

<?php

$indent = 5;
/* Number of spaces to indent per level */
$reader = new XMLReader();
$reader->open('relaxNG.xml');
/*
Example setting relaxNG using string:
$reader->setRelaxNGSchemaSource(file_get_contents('relaxNG.rng'));
*/
if ($reader->setRelaxNGSchema('relaxNG.rng')) {
    while ($reader->read()) {
        /* Print node name indenting it based on depth and $indent var */
        print str_repeat(" ", $reader->depth * $indent) . $reader->name . "\n";
    }
}
print "\n";
if (!$reader->isValid()) {
    print "Document is not valid\n";
} else {
    print "Document is valid\n";
}
开发者ID:cefalo19,项目名称:php-src,代码行数:22,代码来源:xmlreader_relaxNG.php


注:本文中的XMLReader::isValid方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。