本文整理汇总了PHP中XMLReader::setRelaxNGSchema方法的典型用法代码示例。如果您正苦于以下问题:PHP XMLReader::setRelaxNGSchema方法的具体用法?PHP XMLReader::setRelaxNGSchema怎么用?PHP XMLReader::setRelaxNGSchema使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XMLReader
的用法示例。
在下文中一共展示了XMLReader::setRelaxNGSchema方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例2: _getReader
protected function _getReader($data, $request)
{
if (!is_bool($request)) {
}
/// @TODO
$this->_currentNode = NULL;
$reader = new XMLReader();
$reader->xml($data, NULL, LIBXML_NONET | LIBXML_NOENT);
if ($this->_validate) {
if ('@data_dir@' != '@' . 'data_dir' . '@') {
$schema = '@data_dir@' . DIRECTORY_SEPARATOR . 'pear.erebot.net' . DIRECTORY_SEPARATOR . 'XRL';
} else {
$schema = dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . 'data';
}
$schema .= DIRECTORY_SEPARATOR;
$schema .= $request ? 'request.rng' : 'response.rng';
$reader->setRelaxNGSchema($schema);
}
return $reader;
}
示例3: chr
<?php
$file = '/etc/passwd' . chr(0) . 'asdf';
$reader = new XMLReader();
var_dump($reader->open($file));
var_dump($reader->setRelaxNGSchema($file));
示例4: 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===
示例5: 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";
}
示例6: getReader
/**
* Returns an XML reader for some data.
*
* \param string $URI
* URI to the XML data to process.
*
* \param bool $request
* Whether the data refers to an XML-RPC
* request (\c true) or a response (\c false).
*
* \retval XMLReader
* An XML reader for the given data.
*
* \throw InvalidArgumentException
* You tried to pass something that is not
* a boolean as the \c $request parameter.
*
* \note
* The reader is set to validate the document
* on the fly if that's what this decoder was
* configured to do during construction.
*/
protected function getReader($URI, $request)
{
if (!is_string($URI)) {
throw new \InvalidArgumentException('Not a string');
}
if (!is_bool($request)) {
throw new \InvalidArgumentException('Not a boolean');
}
$this->currentNode = null;
$reader = new \XMLReader();
$reader->open($URI, null, LIBXML_NONET | LIBXML_NOENT);
if ($this->validate) {
$schema = dirname(__DIR__) . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR;
$schema .= $request ? 'request.rng' : 'response.rng';
$reader->setRelaxNGSchema($schema);
}
return $reader;
}
示例7: 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;
}
示例8: setRelaxNGSchema
public function setRelaxNGSchema($filename)
{
return parent::setRelaxNGSchema($filename);
}