本文整理汇总了PHP中XMLReader::readInnerXml方法的典型用法代码示例。如果您正苦于以下问题:PHP XMLReader::readInnerXml方法的具体用法?PHP XMLReader::readInnerXml怎么用?PHP XMLReader::readInnerXml使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XMLReader
的用法示例。
在下文中一共展示了XMLReader::readInnerXml方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: readXml
/**
* Read an XML snippet from an element
*
* @param string $metafield Field that we will fill with the result
* @throws MWException
*/
private function readXml($metafield = null)
{
$this->debug("Read top level metadata");
if (!$metafield || $this->reader->nodeType != XMLReader::ELEMENT) {
return;
}
// @todo Find and store type of xml snippet. metadata['metadataType'] = "rdf"
if (method_exists($this->reader, 'readInnerXML')) {
$this->metadata[$metafield] = trim($this->reader->readInnerXml());
} else {
throw new MWException("The PHP XMLReader extension does not come " . "with readInnerXML() method. Your libxml is probably out of " . "date (need 2.6.20 or later).");
}
$this->reader->next();
}
示例2: getCurrencyExchangeRates
private function getCurrencyExchangeRates(\XMLReader $xml)
{
switch ($xml->localName) {
case 'Cube':
$this->currencyDetails['CXD'] = strtotime($xml->getAttribute('date'));
break;
case 'Rate':
$multiplier = 1;
if (!is_null($xml->getAttribute('multiplier'))) {
$multiplier = $xml->getAttribute('multiplier');
}
$this->currencyDetails['CXV'][$xml->getAttribute('currency')] = $xml->readInnerXml() / $multiplier;
break;
}
}
示例3: getWeatherData
private function getWeatherData($unit)
{
if ($this->city != "") {
$additionalParameter = "";
if ($unit == "c") {
$additionalParameter .= "&units=metric";
}
$url = $this->basicUrl . $this->city . $this->fixUrlParameter . $additionalParameter;
//OCP\Util::writeLog('ocDashboard',"openweather xml url: ".$url, \OCP\Util::DEBUG);
$reader = new XMLReader();
$reader->open($url);
$data = array();
while ($reader->read()) {
if ($reader->nodeType == XMLReader::ELEMENT) {
if (isset($this->xmlNodeAttributes[$reader->name])) {
$n = 0;
while (isset($data[$n][$reader->name])) {
$n++;
}
foreach ($this->xmlNodeAttributes[$reader->name] as $key) {
$data[$n][$reader->name][$key] = $reader->getAttribute($key);
}
if (in_array($reader->name, $this->xmlAddUnit)) {
$data[$n][$reader->name]['unit'] = $this->getUnit($reader->name, $unit);
}
} else {
if (isset($this->xmlNodeValueKeys[$reader->name])) {
$data[$reader->name] = $reader->readInnerXml();
}
}
}
}
$reader->close();
if (count($data) > 0) {
$this->weatherData = $data;
} else {
OCP\Util::writeLog('ocDashboard', "openweather - could not fetch data for " . $this->city, \OCP\Util::ERROR);
$this->errorMsg = $this->l->t("Could not fetch data for \"%s\".<br>Please try another value.<br><a href='%s'>» settings</a>", array($this->city, \OCP\Util::linkToRoute('settings_personal')));
}
}
}
示例4: Time
}
if ($x->localName === 'lastUpdated' && $x->nodeType == XMLREADER::ELEMENT) {
$event[eventModified] = $x->readString();
}
if ($x->localName === 'jobType' && $x->nodeType == XMLREADER::ELEMENT) {
$event[eventType] = $x->readString();
}
if ($x->localName === 'significance' && $x->nodeType == XMLREADER::ELEMENT) {
$event[description] .= ". " . $x->readString();
}
if ($x->localName === 'timeOfDay' && $x->nodeType == XMLREADER::ELEMENT) {
$event[description] .= ". Time(s) of day affected: " . $x->readString();
}
if ($x->localName === 'trafficImpacts' && $x->nodeType == XMLREADER::ELEMENT) {
$event[trafficImpactsXML] = "<root>";
$event[trafficImpactsXML] .= $x->readInnerXml();
$event[trafficImpactsXML] .= "</root>";
}
if ($x->localName === 'locations' && $x->nodeType == XMLREADER::ELEMENT) {
$event[geoXML] = "<root>";
$event[geoXML] .= $x->readInnerXML();
$event[geoXML] .= "</root>";
$events[] = $event;
}
}
$x->close();
######## CREATE GEOJSON ######## CREATE GEOJSON ######## CREATE GEOJSON ######
$eventsCount = sizeof($events);
$x2GeoStruct = array();
$x2ImpactStruct = array();
$toBeEncoded1 = array("type" => "FeatureCollection", "features" => []);
示例5: XMLReader
<?php
/* $Id$ */
$xmlstring = '<?xml version="1.0" encoding="UTF-8"?>
<books><book>test</book></books>';
$reader = new XMLReader();
$reader->XML($xmlstring);
$reader->read();
echo $reader->readInnerXml();
echo "\n";
$reader->close();
$reader = new XMLReader();
$reader->XML($xmlstring);
$reader->read();
echo $reader->readOuterXml();
echo "\n";
$reader->close();
?>
===DONE===
示例6: _readElementAsType
/**
* @param \XMLReader $xml
* @param string $type
* @param bool $root
* @throws \Exception
* @return mixed
*/
protected function _readElementAsType($xml, $type, $root = false)
{
if (isset(self::$_knownSimpleTypes[$type])) {
$ret = $this->_decodeSimpleValue($xml->readInnerXml(), $type);
if (!$xml->isEmptyElement) {
$open = 1;
while ($open > 0) {
if (!$xml->read()) {
throw new \Exception("XML Read failure parsing simple value");
}
if ($xml->nodeType == \XMLReader::ELEMENT && !$xml->isEmptyElement) {
$open++;
} elseif ($xml->nodeType == \XMLReader::END_ELEMENT) {
$open--;
}
}
}
return $ret;
}
// Assume type strings are well formed: look for the last [ to see if it's an array or map.
// Note that this might be an array of arrays, and we're after the outermost type, so we're after the last [!
$pos = strrpos($type, '[');
if ($pos === false) {
// If there wasn't a [ then this must be an object.
return $this->_readObject($xml, $type, $root);
}
// Extract the base type, and whatever's between the [...] as the index type.
// Potentially the type string is actually badly formed:
// e.g. this code will accept string[int! as being an array of string with index int.
// Bah. I'll ignore that case for now. This bit of code gets called a lot, I'd rather not add another substr.
$elementType = substr($type, 0, $pos);
$indexType = substr($type, $pos + 1, -1);
// We return an array of the element(s) we've read.
// This will be merged if necessary by whoever we return it to.
if ($indexType === "") {
// It's an array element, not a map.
return array($this->_readElementAsType($xml, $elementType));
} else {
return $this->_readMap($xml, $indexType, $elementType);
}
}
示例7: Decode
public static function Decode($SOAPResponse, &$isSOAPFault)
{
$responseXML = "";
try {
if (empty($SOAPResponse)) {
throw new Exception("Given Response is not a valid SOAP response.");
}
$xmlDoc = new XMLReader();
$res = $xmlDoc->XML($SOAPResponse);
if ($res) {
while (trim(strtoupper($xmlDoc->localName)) != self::$SOAPBody) {
$isNotEnd = $xmlDoc->read();
if (!$isNotEnd) {
break;
}
}
if (!$isNotEnd) {
$isSOAPFault = true;
$soapFault = new FaultMessage();
$errorData = new ErrorData();
$errorData->errorId = 'Given Response is not a valid SOAP response.';
$errorData->message = 'Given Response is not a valid SOAP response.';
$soapFault->error = $errorData;
return $soapFault;
}
$responseXML = $xmlDoc->readInnerXml();
$xmlDOM = new DOMDocument();
$xmlDOM->loadXML($responseXML);
$count = 0;
$xmlDoc->read();
$isSOAPFault = trim(strtoupper($xmlDoc->localName)) == self::$SOAPFault;
if ($isSOAPFault) {
while (trim(strtoupper($xmlDoc->localName)) != self::$SOAPFaultMessage) {
$isNotEnd = $xmlDoc->read();
if (!$isNotEnd) {
break;
}
}
$xmlDOM->loadXML($xmlDoc->readOuterXml());
}
switch ($xmlDoc->nodeType) {
case XMLReader::ELEMENT:
$nodeName = $xmlDoc->localName;
$prefix = $xmlDoc->prefix;
if (class_exists($nodeName)) {
$xmlNodes = $xmlDOM->getElementsByTagName($nodeName);
foreach ($xmlNodes as $xmlNode) {
//$xmlNode->prefix = "";
$xmlNode->setAttribute("_class", $nodeName);
$xmlNode->setAttribute("_type", "object");
}
}
break;
}
$responseXML = $xmlDOM->saveXML();
$unserializer = new XML_Unserializer();
$unserializer->setOption(XML_UNSERIALIZER_OPTION_COMPLEXTYPE, 'object');
$res = $unserializer->unserialize($responseXML, false);
if ($res) {
$responseXML = $unserializer->getUnserializedData();
}
$xmlDoc->close();
} else {
throw new Exception("Given Response is not a valid SOAP response.");
}
} catch (Exception $ex) {
throw $ex;
throw new Exception("Error occurred while Soap decoding: " . $ex->getMessage());
}
return $responseXML;
}
示例8: parse
//.........这里部分代码省略.........
case 'nil':
// Next: value, $tagName
$nextExpectedElements = 0b1000000000000000000010000 | ${'flag' . $tagName};
$type = $tagName;
$aggregates[$depth + 1] = null;
break;
case 'int':
case 'i4':
case 'i2':
case 'i1':
// Next: value, #text, $tagName
$nextExpectedElements = 0b100010000 | ${'flag' . $tagName};
$type = $tagName;
$aggregates[$depth + 1] = 0;
break;
case 'boolean':
// Next: value, #text, $tagName
$nextExpectedElements = 0b100010000 | ${'flag' . $tagName};
$type = 'boolean';
$aggregates[$depth + 1] = false;
break;
case 'double':
case 'float':
case 'bigdecimal':
// Next: value, #text, $tagName
$nextExpectedElements = 0b100010000 | ${'flag' . $tagName};
$type = $tagName;
$aggregates[$depth + 1] = 0.0;
break;
case 'dom':
$type = 'dom';
// Disable type checking
$nextExpectedElements = null;
$aggregates[$depth + 1] = $xml->readInnerXml();
break;
}
break;
case \XMLReader::END_ELEMENT:
switch ($tagName) {
case 'params':
case 'fault':
break 3;
case 'param':
// Next: params, param
$nextExpectedElements = 0b1010;
break;
case 'value':
$nextExpectedElements = 0b100100000011100100011011100;
$aggregates[$depth][] = $aggregates[$depth + 1];
break;
case 'array':
case 'struct':
--$depth;
// Break intentionally omitted
// Break intentionally omitted
case 'string':
case 'int':
case 'biginteger':
case 'i8':
case 'i4':
case 'i2':
case 'i1':
case 'boolean':
case 'double':
case 'float':
case 'bigdecimal':
示例9: readHelpDocument
/**
* Extract the contents of the first div tag in the XHTML help document
*
* @return string
* @throws \Nethgui\Exception\HttpException
*/
protected function readHelpDocument($filePath)
{
$document = new \XMLReader();
set_error_handler(function ($errno, $errstr) {
}, E_WARNING | E_NOTICE);
if ($document->open('file://' . $filePath, 'utf-8', LIBXML_NOENT) === TRUE) {
// Advance to BODY tag:
while ($document->name != 'body' && $document->read()) {
}
while ($document->name != 'div' && $document->read()) {
}
$content = $document->readInnerXml();
} else {
$content = 'Not found';
throw new \Nethgui\Exception\HttpException(sprintf("%s: resource not found", __CLASS__), 404, 1333119424);
}
restore_error_handler();
return $this->expandIncludes($content);
}
示例10: readInnerXml
public function readInnerXml()
{
return parent::readInnerXml();
}
示例11: getSurroundingElement
/**
* This function should determine the correct way to wrap a given html snipped to produce valid html.
* - for a transparent content model element T the function is called recursively to determine the content model of T.
* - phrasing content is a subset of flow content.
* - div may contain any flow content and is allowed wherever flow content is allowed.
* - span may contain phrasing content only and is only allowed where phrasing content is expected.
*
* Thus as soon as we find any flow content element that is not phrasing content, we use div;
* else we use span.
*
* @param $content string: the html code we want to wrap in a semantically meaningless element
* @return string the tag name to wrap the content in a valid way.
*/
public function getSurroundingElement($content)
{
$xml = new XMLReader();
$wrappedContent = "<root>{$content}</root>";
$xml->XML($wrappedContent);
$debugTrace = '';
// $phrasingContentElements = [
// 'a', 'abbr', 'area', 'audio',
// 'b', 'bdi', 'bdo', 'br', 'button',
// 'canvas', 'cite', 'code',
// 'data', 'datalist', 'del', 'dfn',
// 'em', 'embed',
// 'i', 'iframe', 'img', 'input', 'ins',
// 'kbd', 'keygen',
// 'label', 'link', //(if it is allowed in the body)
// 'map', 'mark', 'math', 'meta' /* (if the itemprop attribute is present) */, 'meter',
// 'noscript',
// 'object', 'output',
// 'picture', 'progress',
// 'q',
// 'ruby',
// 's', 'samp', 'script', 'select', 'small', 'span', 'strong', 'sub', 'sup', 'svg',
// 'template', 'textarea', 'time',
// 'u',
// 'var', 'video',
// 'wbr'
// // text elements
// ];
$notPhrasingFlowContentElements = ['address', 'article', 'aside', 'blockquote', 'details', 'dialog', 'div', 'dl', 'fieldset', 'figure', 'footer', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'header', 'hgroup', 'hr', 'main', 'mark', 'menu', 'meter', 'nav', 'p', 'pre', 'section', 'style', 'table', 'ul'];
$transparentElements = ['a', 'ins', 'del', 'object', 'map', 'noscript', 'canvas'];
ob_start();
//"warningCallback");
$xml->read();
// go to the root node
$xml->read();
// skip the root node
do {
$debugTrace .= $xml->name . '(';
//.$read.'#';
if ($xml->nodeType == XMLReader::ELEMENT) {
// if element name is a notPhrasingFlowContentElement, we can return div:
$normalizedName = strtolower($xml->name);
if (in_array($normalizedName, $transparentElements)) {
$contentModelFromRecursion = $this->getSurroundingElement($xml->readInnerXml());
if ($contentModelFromRecursion['errorOccurred']) {
return array('nodeName' => 'span', 'trace' => $debugTrace, 'errorOccurred' => true);
} elseif ($contentModelFromRecursion['nodeName'] == 'div') {
$debugTrace = $debugTrace . $contentModelFromRecursion['trace'] . ')';
return array('nodeName' => 'div', 'trace' => $debugTrace);
}
} elseif (in_array($normalizedName, $notPhrasingFlowContentElements)) {
$debugTrace = $debugTrace . ')';
return array('nodeName' => 'div', 'trace' => $debugTrace);
}
}
} while ($read = $xml->next());
$buffer = ob_get_clean();
$anyErrorOccurred = !empty($buffer);
$debugTrace = $debugTrace . ')';
return array('nodeName' => 'span', 'trace' => $debugTrace, 'errorOccurred' => $anyErrorOccurred);
}