本文整理汇总了PHP中XMLReader::readOuterXml方法的典型用法代码示例。如果您正苦于以下问题:PHP XMLReader::readOuterXml方法的具体用法?PHP XMLReader::readOuterXml怎么用?PHP XMLReader::readOuterXml使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XMLReader
的用法示例。
在下文中一共展示了XMLReader::readOuterXml方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: parseFile
/**
* @param \Closure $callback
*/
protected function parseFile(\Closure $callback)
{
while ($this->xmlr->localName == $this->node) {
try {
$sxe = new \SimpleXMLElement($this->xmlr->readOuterXml());
if (!$sxe instanceof \SimpleXMLElement) {
throw new \Exception("node is note SimpleXMLElement");
}
$callback($sxe);
} catch (\RuntimeException $e) {
throw new \RuntimeException($e->getMessage());
} catch (\Exception $e) {
if ($this->trace) {
echo sprintf("%s - %s - %s -%s\n", $e->getMessage(), $e->getFile(), $e->getLine(), $e->getTraceAsString());
}
if ($this->strict) {
throw new \RuntimeException($e->getMessage());
}
}
if ($this->debug) {
break;
}
$this->xmlr->next($this->node);
}
$this->xmlr->close();
}
示例2: parse
/**
* Method to parse the feed into a JFeed object.
*
* @return JFeed
*
* @since 12.3
*/
public function parse()
{
$feed = new JFeed();
// Detect the feed version.
$this->initialise();
// Let's get this party started...
do {
// Expand the element for processing.
$el = new SimpleXMLElement($this->stream->readOuterXml());
// Get the list of namespaces used within this element.
$ns = $el->getNamespaces(true);
// Get an array of available namespace objects for the element.
$namespaces = array();
foreach ($ns as $prefix => $uri) {
// Ignore the empty namespace prefix.
if (empty($prefix)) {
continue;
}
// Get the necessary namespace objects for the element.
$namespace = $this->fetchNamespace($prefix);
if ($namespace) {
$namespaces[] = $namespace;
}
}
// Process the element.
$this->processElement($feed, $el, $namespaces);
// Skip over this element's children since it has been processed.
$this->moveToClosingElement();
} while ($this->moveToNextElement());
return $feed;
}
示例3: Decode
public static function Decode($XMLResponse, &$isFault)
{
$responseXML = null;
try {
if (empty($XMLResponse)) {
throw new Exception("Given Response is not a valid SOAP response.");
}
$xmlDoc = new XMLReader();
$res = $xmlDoc->XML($XMLResponse);
if ($res) {
$xmlDoc->read();
$responseXML = $xmlDoc->readOuterXml();
$xmlDOM = new DOMDocument();
$xmlDOM->loadXML($responseXML);
$isFault = trim(strtoupper($xmlDoc->localName)) == self::$FaultMessage;
if ($isFault) {
$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 XML response.");
}
} catch (Exception $ex) {
throw new Exception("Error occurred while XML decoding");
}
return $responseXML;
}
开发者ID:christopherreay,项目名称:freeFreeCrowdfunding_ignitiondeck_crowdfunding,代码行数:48,代码来源:XMLEncoder.php
示例4: validate
/**
* @param FeedTypeInterface $type
* @param OutputInterface $output
*
* @return int
*/
protected function validate(FeedTypeInterface $type, OutputInterface $output)
{
$file = $this->exporter->getFeedFilename($type);
if (!file_exists($file)) {
throw new FileNotFoundException(sprintf('<error>Feed "%s" has not yet been exported</error>', $type->getName()));
}
$options = LIBXML_NOENT | LIBXML_COMPACT | LIBXML_PARSEHUGE | LIBXML_NOERROR | LIBXML_NOWARNING;
$this->reader = new \XMLReader($options);
$this->reader->open($file);
$this->reader->setParserProperty(\XMLReader::SUBST_ENTITIES, true);
// foreach ($type->getNamespaces() as $name => $location) {
// $this->reader->setSchema($location);
// }
libxml_clear_errors();
libxml_use_internal_errors(true);
libxml_disable_entity_loader(true);
$progress = new ProgressBar($output);
$progress->start();
// go through the whole thing
while ($this->reader->read()) {
if ($this->reader->nodeType === \XMLReader::ELEMENT && $this->reader->name === $type->getItemNode()) {
$progress->advance();
$this->currentItem = $this->reader->readOuterXml();
}
if ($error = libxml_get_last_error()) {
throw new \RuntimeException(sprintf('[%s %s] %s (in %s - line %d, column %d)', LIBXML_ERR_WARNING === $error->level ? 'WARNING' : 'ERROR', $error->code, trim($error->message), $error->file ? $error->file : 'n/a', $error->line, $error->column));
}
}
$progress->finish();
}
示例5: readFromPath
/**
* @param $xmlFilePath
* @return \Generator|Product[]
*/
public function readFromPath($xmlFilePath)
{
$xml = new \XMLReader();
$xml->open($xmlFilePath);
while ($xml->read() && $xml->name !== 'product') {
}
$decoder = new XmlDecoder();
while ($xmlData = $xml->readOuterXml()) {
(yield $decoder->decodeProduct(new \SimpleXMLElement($xmlData)));
$xml->next('product');
}
$xml->close();
}
示例6: readOuterXml
/**
* Decorated method
*
* @throws BadMethodCallException in case XMLReader can not expand the node
* @return string
*/
public function readOuterXml()
{
// Compatibility libxml 20620 (2.6.20) or later - LIBXML_VERSION / LIBXML_DOTTED_VERSION
if (method_exists($this->reader, 'readOuterXml')) {
return $this->reader->readOuterXml();
}
if (0 === $this->reader->nodeType) {
return '';
}
$doc = new DOMDocument();
$doc->preserveWhiteSpace = false;
$doc->formatOutput = true;
$node = $this->expand($doc);
return $doc->saveXML($node);
}
示例7: streamXml
public function streamXml()
{
$reader = new XMLReader();
$reader->open($this->getUrl());
while ($reader->next()) {
while (!($reader->nodeType == XMLReader::ELEMENT && $reader->name == $this->getElement())) {
if (!$reader->read()) {
break 2;
}
//Break if something wrong
}
if ($reader->nodeType == XMLReader::ELEMENT && $reader->name == $this->getElement()) {
(yield simplexml_load_string($reader->readOuterXml(), null, LIBXML_NOCDATA));
//Yield load XML to save time and pressure
$reader->next();
}
}
}
示例8: parse
/**
* @param $date
* @return CurrencyRaw[]
*/
public function parse($date)
{
$xml = new XMLReader();
$url = $this->getUrl($date);
$temp_file = tempnam(sys_get_temp_dir(), 'currency-source');
$fp = fopen($temp_file, 'w+');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_exec($ch);
curl_close($ch);
fclose($fp);
$xml->open($temp_file);
$xml->setParserProperty(XMLReader::VALIDATE, false);
Yii::log('Open XML from `' . $url . '`', CLogger::LEVEL_INFO, 'currency-parser');
$data = [];
while ($xml->read()) {
if ($xml->nodeType == XMLReader::ELEMENT && $xml->localName == $this->xmlElement) {
$xmlRow = null;
try {
$xmlRow = new SimpleXMLElement($xml->readOuterXml());
} catch (Exception $e) {
continue;
}
if ($rowObj = $this->parseRow($xmlRow)) {
$data[$rowObj->num_code] = $rowObj;
// Yii::log('Parsed XML row `' . json_encode($rowObj) . '`', CLogger::LEVEL_INFO, 'currency-parser');
} else {
Yii::log('Error parsed XML row', CLogger::LEVEL_WARNING, 'currency-parser');
}
}
}
@unlink($temp_file);
return $data;
}
示例9: 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===
示例10: _getRecord
/**
* Get the xml content of a record for the specified prefix.
*
* @see OaiPmhGateway_ResponseGenerator::_getRecord()
*
* @param string $identifier
* @param string $prefix
* @return SimpleXml|null|boolean The record if found, null if not found,
* false if error (incorrect format). The error is set if any.
*/
protected function _getRecord($identifier, $metadataPrefix)
{
// Prepare the xml reader for the existing static repository.
// Don't use a static value to allow tests.
$localRepositoryFilepath = $this->_folder->getLocalRepositoryFilepath();
if (!file_exists($localRepositoryFilepath)) {
return false;
}
// Read the xml from the beginning.
$reader = new XMLReader();
$result = $reader->open($localRepositoryFilepath, null, LIBXML_NSCLEAN);
if (!$result) {
$localRepositoryFilepath = false;
return false;
}
$record = null;
while ($reader->read()) {
if ($reader->nodeType == XMLReader::ELEMENT && $reader->name == 'ListRecords' && $reader->getAttribute('metadataPrefix') === $metadataPrefix) {
// Loop on all records until the one of the identifier (if
// prefix is not found above, it's bypassed because there is no
// new element to read.
while ($reader->read()) {
if ($reader->nodeType == XMLReader::ELEMENT && $reader->name === 'oai:record') {
// Because XMLReader is a stream reader, forward only,
// and the identifier is not the first element, it is
// saved temporary.
$currentRecord = $reader->readOuterXml();
$recordXml = @simplexml_load_string($currentRecord, 'SimpleXMLElement', 0, 'oai', true);
// Check conditions.
if ((string) $recordXml->header->identifier === $identifier) {
$record = $recordXml;
break 2;
}
$reader->next();
}
// Don't continue to list records with another prefix.
if ($reader->nodeType == XMLReader::END_ELEMENT && $reader->name == 'ListRecords') {
break 2;
}
}
}
}
$reader->close();
return $record;
}
示例11: processXML
/**
* Process the XML
*/
private function processXML()
{
// init object
$reader = new XMLReader();
// open the file
$reader->open(FRONTEND_FILES_PATH . '/blogger.xml');
// start reading
$reader->read();
// loop through the document
while (true) {
// start tag for entry?
if ($reader->name != 'entry') {
continue;
}
// end tag?
if ($reader->nodeType == XMLReader::END_ELEMENT) {
$reader->next();
}
// get the raw XML
$xmlString = $reader->readOuterXml();
// is it really an entry?
if (substr($xmlString, 0, 6) == '<entry') {
// read the XML as an SimpleXML-object
$xml = @simplexml_load_string($reader->readOuterXml());
// skip element if it isn't a valid SimpleXML-object
if ($xml === false) {
continue;
}
// loop the categories
foreach ($xml->category as $category) {
// post
if ($category['term'] == 'http://schemas.google.com/blogger/2008/kind#post') {
// process the post
$this->processXMLAsPost($xml);
// stop looping
break;
}
// comment
if ($category['term'] == 'http://schemas.google.com/blogger/2008/kind#comment') {
// process the post
$this->processXMLAsComment($xml);
// stop looping
break;
}
}
}
// end
if (!$reader->read()) {
break;
}
}
// close
$reader->close();
}
示例12: loadElementXml
/**
* @return \SimpleXMLElement
*/
protected function loadElementXml()
{
$xml = $this->xmlReader->readOuterXml();
return simplexml_load_string('<?xml version="1.0" encoding="UTF-8"?>' . $xml);
}
示例13: 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;
}
示例14: parse
/**
* {@inheritdoc}
*/
public function parse($xmlString)
{
if ($this->validateResponse) {
XmlChecker::isValid($xmlString);
}
$useErrors = libxml_use_internal_errors(true);
$xml = new \XMLReader();
$xml->xml($xmlString, 'UTF-8', LIBXML_COMPACT | LIBXML_NOCDATA | LIBXML_NOBLANKS | LIBXML_PARSEHUGE);
$xml->setParserProperty(\XMLReader::VALIDATE, false);
$xml->setParserProperty(\XMLReader::LOADDTD, false);
// This following assignments are auto-generated using Fxmlrpc\Serialization\CodeGenerator\XmlReaderParserBitmaskGenerator
// Don’t edit manually
static $flagmethodResponse = 0b1;
static $flagparams = 0b10;
static $flagfault = 0b100;
static $flagparam = 0b1000;
static $flagvalue = 0b10000;
static $flagarray = 0b100000;
static $flagmember = 0b1000000;
static $flagname = 0b10000000;
${'flag#text'} = 0b100000000;
static $flagstring = 0b1000000000;
static $flagstruct = 0b10000000000;
static $flagint = 0b100000000000;
static $flagbiginteger = 0b1000000000000;
static $flagi8 = 0b10000000000000;
static $flagi4 = 0b100000000000000;
static $flagi2 = 0b1000000000000000;
static $flagi1 = 0b10000000000000000;
static $flagboolean = 0b100000000000000000;
static $flagdouble = 0b1000000000000000000;
static $flagfloat = 0b10000000000000000000;
static $flagbigdecimal = 0b100000000000000000000;
${'flagdateTime.iso8601'} = 0b1000000000000000000000;
static $flagdateTime = 0b10000000000000000000000;
static $flagbase64 = 0b100000000000000000000000;
static $flagnil = 0b1000000000000000000000000;
static $flagdom = 0b10000000000000000000000000;
static $flagdata = 0b100000000000000000000000000;
// End of auto-generated code
$aggregates = [];
$depth = 0;
$nextExpectedElements = 0b1;
$i = 0;
$isFault = false;
while ($xml->read()) {
++$i;
$nodeType = $xml->nodeType;
if ($nodeType === \XMLReader::COMMENT || $nodeType === \XMLReader::DOC_TYPE || $nodeType === \XMLReader::SIGNIFICANT_WHITESPACE && ($nextExpectedElements & 0b100000000) !== 0b100000000) {
continue;
}
if ($nodeType === \XMLReader::ENTITY_REF) {
return '';
}
$tagName = $xml->localName;
if ($nextExpectedElements !== null && ($flag = isset(${'flag' . $tagName}) ? ${'flag' . $tagName} : -1) && ($nextExpectedElements & $flag) !== $flag) {
throw new UnexpectedTagException($tagName, $nextExpectedElements, get_defined_vars(), $xml->depth, $xml->readOuterXml());
}
processing:
switch ($nodeType) {
case \XMLReader::ELEMENT:
switch ($tagName) {
case 'methodResponse':
// Next: params, fault
$nextExpectedElements = 0b110;
break;
case 'params':
// Next: param
$nextExpectedElements = 0b1000;
$aggregates[$depth] = [];
break;
case 'fault':
$isFault = true;
// Break intentionally omitted
// Break intentionally omitted
case 'param':
// Next: value
$nextExpectedElements = 0b10000;
break;
case 'array':
$aggregates[++$depth] = [];
// Break intentionally omitted
// Break intentionally omitted
case 'data':
// Next: array, data, value
$nextExpectedElements = 0b100000000000000000000110000;
break;
case 'struct':
// Next: struct, member, value
$nextExpectedElements = 0b10001010000;
$aggregates[++$depth] = [];
break;
case 'member':
// Next: name, value
$nextExpectedElements = 0b10010000;
$aggregates[++$depth] = [];
break;
//.........这里部分代码省略.........
示例15: import
public function import($filename, $type = null, $external_source = null, $import_size = null)
{
if (!$filename) {
$this->usageError('Import filename required');
}
if (!file_exists($filename)) {
$this->usageError("Cannot find import file " . $filename);
}
$type && ($this->type = $type);
$external_source && ($this->external_source = $external_source);
$import_size && ($this->import_size = $import_size);
$connection = Yii::app()->db;
$cmd = $connection->createCommand('ALTER TABLE medication_drug DISABLE KEYS;');
$cmd->execute();
$xr = new XMLReader();
$xr->open($filename);
$count = 0;
$rows = array();
$filter_regex = "/" . join('|', $this->filter_list) . "/i";
switch ($this->type) {
case 'vtm':
// get to the start
while ($xr->read() && $xr->name !== 'VTM') {
}
// iterate through
while ($xr->name === 'VTM') {
$node = new SimpleXMLElement($xr->readOuterXml());
$rows[] = implode(",", array($connection->quoteValue($node->NM), $connection->quoteValue($node->VTMID), $connection->quoteValue('DMD-VTM')));
$xr->next('VTM');
if (++$count % $this->import_size == 0) {
$this->importMD($rows);
}
}
break;
case 'vmp':
// get to the start
while ($xr->read() && $xr->name !== 'VMP') {
}
// iterate through
while ($xr->name === 'VMP') {
$node = new SimpleXMLElement($xr->readOuterXml());
if ($node->VTMID || preg_match($filter_regex, $node->NM)) {
$xr->next('VMP');
continue;
}
$rows[] = implode(',', array($connection->quoteValue($node->NM), $connection->quoteValue($node->VPID), $connection->quoteValue('DMD-VMP')));
$xr->next('VMP');
if (++$count % $this->import_size == 0) {
$this->importMD($rows);
}
}
break;
default:
echo "Unrecognised format " . $this->type . "\n\n";
echo $this->getHelp();
}
// be good
$xr->close();
// import remainder
if (count($rows)) {
$this->importMD($rows);
}
// turn the indexes back on
$cmd = $connection->createCommand('ALTER TABLE medication_drug ENABLE KEYS;');
$cmd->execute();
}