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


PHP XMLReader::expand方法代码示例

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


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

示例1: read

 /**
  * @return array
  */
 public function read()
 {
     $products = [];
     while ($this->xml->read()) {
         if ($this->isProductNode()) {
             $node = $this->xml->expand();
             $products[] = $this->createProduct($node);
         }
     }
     return $products;
 }
开发者ID:nfq-eta,项目名称:test-workshop,代码行数:14,代码来源:XmlProductReader.php

示例2: current

 /**
  * @inheritdoc
  */
 public function current()
 {
     if (!isset($this->xmlReader)) {
         throw new \RuntimeException('The resource needs to be open.');
     }
     if (!$this->xmlReader->name) {
         return false;
     }
     /** @var \DOMElement $data */
     $data = $this->xmlReader->expand();
     $data = $this->xmlKit->convertDomElementToArray($data);
     return array('value' => $data);
 }
开发者ID:yosmanyga,项目名称:resource,代码行数:16,代码来源:XmlFileReader.php

示例3: processFile

 /**
  * Processes given xml file by iterating over product nodes and extracting data into array
  * @param string $filePath
  * @return boolean
  */
 public function processFile($filePath)
 {
     $messageHandler = Mage::getSingleton('xmlimport/messageHandler');
     /* @var $productBuilder C4B_XmlImport_Model_Products_ProductBuilder */
     $productBuilder = Mage::getModel('xmlimport/products_productBuilder');
     $productNodePosition = 0;
     $xmlReader = new XMLReader();
     $xmlReader->open($filePath);
     $products = array();
     while ($xmlReader->read()) {
         if ($xmlReader->nodeType != XMLReader::ELEMENT || $xmlReader->name != self::XML_NODE_NAME_PRODUCT) {
             continue;
         }
         $productNodePosition++;
         $productData = $productBuilder->getProductData($xmlReader->expand());
         if (count($productBuilder->getErrors()) > 0) {
             $messageHandler->addError("Product at position {$productNodePosition} has errors:");
         }
         if ($productData == null) {
             $messageHandler->addError('Product will not be imported');
         } else {
             foreach ($productData as $productDataRow) {
                 $products[] = $productDataRow;
             }
         }
         $messageHandler->addErrorsForFile(basename($filePath), $productNodePosition, $productBuilder->getErrors());
     }
     return $products;
 }
开发者ID:bluevisiontec,项目名称:xmlimport,代码行数:34,代码来源:Products.php

示例4: parse

 /**
  * Parses a specific XML file
  *
  * @param string $inputFile File to parse
  * @return \Generator
  */
 public function parse($inputFile)
 {
     $DCNamespace = 'http://purl.org/rss/1.0/modules/content/';
     $WPNamespace = 'http://wordpress.org/export/1.2/';
     $reader = new \XMLReader();
     $dom = new \DOMDocument('1.0', 'UTF-8');
     $reader->open($inputFile);
     while ($reader->read() && $reader->name !== 'item') {
     }
     while ($reader->name == 'item') {
         $xml = simplexml_import_dom($dom->importNode($reader->expand(), true));
         $wpItems = $xml->children($WPNamespace);
         $content = $xml->children($DCNamespace)->encoded;
         $categories = [];
         $tags = [];
         foreach ($xml->category as $category) {
             if ('category' == $category->attributes()->domain) {
                 $categories[] = (string) $category;
             }
             if ('post_tag' == $category->attributes()->domain) {
                 $tags[] = (string) $category;
             }
         }
         if ($wpItems) {
             $post_type = (string) $wpItems->post_type;
             $data = ['type' => $post_type, 'post_date' => new \DateTime((string) $wpItems->post_date), 'title' => (string) $xml->title, 'content' => (string) $content, 'tags' => $tags, 'categories' => $categories];
             (yield $data);
         }
         $reader->next('item');
     }
 }
开发者ID:dragonmantank,项目名称:fillet,代码行数:37,代码来源:WordpressExport.php

示例5: parse

 /**
  * Parses a MySQL dump XML file.
  *
  * @param $source
  * @return Fixture
  * @throws \TheIconic\Fixtures\Exception\InvalidParserException
  */
 public function parse($source)
 {
     $fixtureArray = [];
     $z = new \XMLReader();
     $z->open($source);
     $doc = new \DOMDocument();
     while ($z->read() && $z->name !== 'table_data') {
     }
     $tableName = $z->getAttribute('name');
     $rowNum = 0;
     while ($z->read() && $z->name !== 'row') {
     }
     while ($z->name === 'row') {
         $node = simplexml_import_dom($doc->importNode($z->expand(), true));
         $totalAttributes = $node->count();
         for ($i = 0; $i < $totalAttributes; $i++) {
             foreach ($node->field[$i]->attributes() as $attribute) {
                 $attribute = (string) $attribute;
                 $value = (string) $node->field[$i];
                 $namespaces = $node->field[$i]->getNamespaces(true);
                 if (empty($namespaces)) {
                     $fixtureArray[$tableName][$rowNum][$attribute] = $value;
                 }
             }
         }
         $rowNum++;
         $z->next('row');
     }
     if (empty($fixtureArray)) {
         throw new InvalidParserException("It was not possible to parse the XML file: {$source}");
     }
     return Fixture::create($fixtureArray);
 }
开发者ID:therpr,项目名称:fixtures,代码行数:40,代码来源:XmlParser.php

示例6: foo

function foo()
{
    for ($i = 0; $i < 100; $i++) {
        $reader = new XMLReader();
        $reader->xml('<?xml version="1.0" encoding="utf-8"?><id>1234567890</id>');
        while ($reader->read()) {
            $reader->expand();
        }
    }
}
开发者ID:badlamer,项目名称:hhvm,代码行数:10,代码来源:xmlreader-leak.php

示例7: current

 /**
  * Return the current element, <b>FALSE</b> on error
  * @link http://php.net/manual/en/iterator.current.php
  * @link http://stackoverflow.com/a/1835324/372654
  * @return false|array|\SimpleXMLElement
  */
 public function current()
 {
     $node = $this->reader->expand();
     if ($node === false) {
         return false;
     }
     $node = $this->doc->importNode($node, true);
     if ($node === false) {
         return false;
     }
     $current = simplexml_import_dom($node);
     if ($current === false) {
         return false;
     }
     if ($this->options["asArray"]) {
         return json_decode(json_encode($current), true);
     } else {
         return $current;
     }
 }
开发者ID:halilim,项目名称:xml-iterator,代码行数:26,代码来源:XmlIterator.php

示例8: expandToSimpleXml

 /**
  * Method to expand the current reader node into a SimpleXML node for more detailed reading
  * and manipulation.
  *
  * @return  SimpleXMLElement
  *
  * @since   3.0
  * @throws  RuntimeException
  */
 protected function expandToSimpleXml()
 {
     // Whizbang!  And now we have a SimpleXMLElement element from the current stream node. **MAGIC** :-)
     $el = simplexml_import_dom($this->_node->importNode($this->stream->expand(), true), 'SimpleXMLElement');
     // Let's take care of some sanity checking.
     if (!$el instanceof SimpleXMLElement) {
         // @codeCoverageIgnoreStart
         throw new RuntimeException('Unable to expand node to SimpleXML element.');
         // @codeCoverageIgnoreEnd
     }
     return $el;
 }
开发者ID:educakanchay,项目名称:educa,代码行数:21,代码来源:parser.php

示例9: getElements

 /**
  *  Generator to read each specified element in turn and return it as a nice object
  *
  *  @param   string  $elementType  The element type that we want to return
  *  @return  \Generator  \DateTime => \GpxReader\GpxElement
  **/
 public function getElements($elementType)
 {
     while ($this->gpxReader->read()) {
         if ($this->gpxReader->nodeType == \XMLREADER::ELEMENT && $this->gpxReader->name == $elementType) {
             $doc = new \DOMDocument('1.0', 'UTF-8');
             $xml = simplexml_import_dom($doc->importNode($this->gpxReader->expand(), true));
             $gpxAttributes = $this->readAttributes($this->gpxReader);
             $gpxElement = $this->readChildren($xml);
             $gpxElement->position = $gpxAttributes;
             (yield $gpxElement->timestamp => $gpxElement);
         }
     }
 }
开发者ID:MarkBaker,项目名称:GeneratorFunctionExamples,代码行数:19,代码来源:GpxHandler.php

示例10: readString

 /**
  * Decorated method
  *
  * @throws BadMethodCallException
  * @return string
  */
 public function readString()
 {
     // Compatibility libxml 20620 (2.6.20) or later - LIBXML_VERSION  / LIBXML_DOTTED_VERSION
     if (method_exists($this->reader, 'readString')) {
         return $this->reader->readString();
     }
     if (0 === $this->reader->nodeType) {
         return '';
     }
     if (false === ($node = $this->reader->expand())) {
         throw new BadMethodCallException('Unable to expand node.');
     }
     return $node->textContent;
 }
开发者ID:hakre,项目名称:xmlreaderiterator,代码行数:20,代码来源:XMLReaderNode.php

示例11: importXML

 public function importXML($file)
 {
     global $opt;
     $xr = new XMLReader();
     if (!$xr->open($file)) {
         $xr->close();
         return;
     }
     $xr->read();
     if ($xr->nodeType != XMLReader::ELEMENT) {
         echo 'error: First element expected, aborted' . "\n";
         return;
     }
     if ($xr->name != 'gkxml') {
         echo 'error: First element not valid, aborted' . "\n";
         return;
     }
     $startupdate = $xr->getAttribute('date');
     if ($startupdate == '') {
         echo 'error: Date attribute not valid, aborted' . "\n";
         return;
     }
     while ($xr->read() && !($xr->name == 'geokret' || $xr->name == 'moves')) {
     }
     $nRecordsCount = 0;
     do {
         if ($xr->nodeType == XMLReader::ELEMENT) {
             $element = $xr->expand();
             switch ($xr->name) {
                 case 'geokret':
                     $this->importGeoKret($element);
                     break;
                 case 'moves':
                     $this->importMove($element);
                     break;
             }
             $nRecordsCount++;
         }
     } while ($xr->next());
     $xr->close();
     setSysConfig('geokrety_lastupdate', date($opt['db']['dateformat'], strtotime($startupdate)));
 }
开发者ID:kratenko,项目名称:oc-server3,代码行数:42,代码来源:geokrety.class.php

示例12: importXML

 function importXML($file)
 {
     global $opt;
     $xr = new XMLReader();
     if (!$xr->open($file)) {
         $xr->close();
         return;
     }
     $xr->read();
     if ($xr->nodeType != XMLReader::ELEMENT) {
         echo 'error: First element expected, aborted' . "\n";
         return;
     }
     if ($xr->name != 'gkxml') {
         echo 'error: First element not valid, aborted' . "\n";
         return;
     }
     $startupdate = $xr->getAttribute('date');
     if ($startupdate == '') {
         echo 'error: Date attribute not valid, aborted' . "\n";
         return;
     }
     while ($xr->read() && !($xr->name == 'geokret' || $xr->name == 'moves')) {
     }
     $nRecordsCount = 0;
     do {
         if ($xr->nodeType == XMLReader::ELEMENT) {
             $element = $xr->expand();
             switch ($xr->name) {
                 case 'geokret':
                     $this->importGeoKret($element);
                     break;
                 case 'moves':
                     $this->importMove($element);
                     break;
             }
             $nRecordsCount++;
         }
     } while ($xr->next());
     $xr->close();
     sql("UPDATE sysconfig SET value = '" . sql_escape($startupdate) . "' WHERE name='geokrety_lastupdate'");
 }
开发者ID:pawelzielak,项目名称:opencaching-pl,代码行数:42,代码来源:geokrety.class.php

示例13: inspect

 /**
  * @param OutputInterface $output
  * @param \SplFileInfo    $feed
  * @param string          $filterExpression
  *
  * @return array<array, integer>
  */
 protected function inspect(OutputInterface $output, \SplFileInfo $feed, $filterExpression)
 {
     $options = LIBXML_NOENT | LIBXML_NONET | LIBXML_COMPACT | LIBXML_PARSEHUGE | LIBXML_NOERROR | LIBXML_NOWARNING;
     $this->reader = new \XMLReader($options);
     $this->reader->open($feed->getPathname());
     $this->reader->setParserProperty(\XMLReader::SUBST_ENTITIES, true);
     libxml_clear_errors();
     libxml_use_internal_errors(true);
     libxml_disable_entity_loader(true);
     $total = 0;
     $results = [];
     $output->writeln(sprintf('Reading <comment>%s</comment>', $feed->getFilename()));
     if ($filterExpression) {
         $output->writeln(sprintf('Filtering nodes with expression "<info>%s</info>"', $filterExpression));
     }
     $progress = new ProgressBar($output);
     $progress->start();
     // go through the whole thing
     while ($this->reader->read()) {
         if ($this->reader->nodeType === \XMLReader::ELEMENT && $this->reader->name === 'listing') {
             $progress->advance();
             ++$total;
             $node = $this->reader->expand();
             $doc = new \DOMDocument();
             $doc->appendChild($node);
             $xpath = new \DOMXPath($doc);
             $xpath->registerNamespace('x', $doc->lookupNamespaceUri($doc->namespaceURI));
             $query = $xpath->evaluate($filterExpression, $node);
             $result = $query instanceof \DOMNodeList ? $query->length : !empty($query);
             if ($result) {
                 $results[] = $node;
             }
         }
     }
     $progress->finish();
     $output->writeln('');
     return [$results, $total];
 }
开发者ID:treehouselabs,项目名称:io-bundle,代码行数:45,代码来源:ExportInspectCommand.php

示例14: getArguments

 private function getArguments(XMLReader $xmlReader)
 {
     $valueList = array();
     $nodeList = $xmlReader->expand();
     foreach ($nodeList->childNodes as $node) {
         switch ($node->nodeName) {
             case 'ref':
                 $valueList[] = new IoCArgumentValue(IoCArgumentValue::VALUETYPE_REF, trim($node->nodeValue));
                 break;
             case 'eval':
                 $valueList[] = new IoCArgumentValue(IoCArgumentValue::VALUETYPE_EVAL, trim($node->nodeValue));
                 break;
             case 'value':
                 $valueList[] = new IoCArgumentValue(IoCArgumentValue::VALUETYPE_VALUE, $node->nodeValue);
                 break;
             case '#text':
                 if (!trim($node->nodeValue)) {
                     continue;
                 }
         }
     }
     return $valueList;
 }
开发者ID:pfm,项目名称:PHP-IoCFactory,代码行数:23,代码来源:IoCXMLParser.class.php

示例15: while

        while ($paragraph->read()) {

            $node_loc = $paragraph->localName;
            // look for elements
            if ($paragraph->nodeType == XMLREADER::ELEMENT && $paragraph->name === 'w:r') {
                $node = trim($paragraph->readInnerXML());
                //echo $node;
                // add <br> tags
                if (strstr($node, '<w:br '))
                    $text .= '<br>';

                // look for formatting tags                    
                $formatting['bold'] = (strstr($node, '<w:b/>')) ? (($formatting['bold'] == 'closed') ? 'open' : $formatting['bold']) : (($formatting['bold'] == 'opened') ? 'close' : $formatting['bold']);
                $formatting['italic'] = (strstr($node, '<w:i/>')) ? (($formatting['italic'] == 'closed') ? 'open' : $formatting['italic']) : (($formatting['italic'] == 'opened') ? 'close' : $formatting['italic']);
                $formatting['underline'] = (strstr($node, '<w:u ')) ? (($formatting['underline'] == 'closed') ? 'open' : $formatting['underline']) : (($formatting['underline'] == 'opened') ? 'close' : $formatting['underline']);
                $str = $paragraph->expand()->textContent;
                // build text string of doc
                $text .= (($formatting['bold'] == 'open') ? '<strong>' : '') .
                        (($formatting['italic'] == 'open') ? '<em>' : '') .
                        (($formatting['underline'] == 'open') ? '<u>' : '') .
                        //htmlentities(iconv('UTF-8', 'ASCII//TRANSLIT',$paragraph->expand()->textContent)).
                        htmlentities($str, ENT_QUOTES, "utf-8") .
                        (($formatting['underline'] == 'close') ? '</u>' : '') .
                        (($formatting['italic'] == 'close') ? '</em>' : '') .
                        (($formatting['bold'] == 'close') ? '</strong>' : '');

                // reset formatting variables
                foreach ($formatting as $key => $format) {
                    if ($format == 'open')
                        $formatting[$key] = 'opened';
                    if ($format == 'close')
开发者ID:HarmonySoftwareSE499,项目名称:VCS_SE499,代码行数:31,代码来源:upload_test_3.php


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