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


PHP XMLReader::next方法代码示例

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


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

示例1: scan

 /**
  * @throws RuntimeException
  * @return array of arrays.
  *         array( 'dumpKey' => array( 'match1', 'match2' ) )
  */
 public function scan()
 {
     $openSuccess = $this->reader->open($this->dumpLocation);
     if (!$openSuccess) {
         throw new RuntimeException('Failed to open XML: ' . $this->dumpLocation);
     }
     $result = array();
     foreach ($this->query as $queryKey => $query) {
         $result[$queryKey] = array();
         // Make sure keys are returned even if empty
     }
     while ($this->reader->read() && $this->reader->name !== 'page') {
     }
     while ($this->reader->name === 'page') {
         $element = new SimpleXMLElement($this->reader->readOuterXML());
         $page = $this->getPageFromElement($element);
         foreach ($this->query as $queryKey => $query) {
             $match = $this->matchPage($page, $query);
             if ($match) {
                 //TODO allow the user to choose what to return
                 $result[$queryKey][] = $page->getTitle()->getTitle();
             }
         }
         $this->reader->next('page');
     }
     $this->reader->close();
     return $result;
 }
开发者ID:addwiki,项目名称:mediawiki-dump,代码行数:33,代码来源:DumpScanner.php

示例2: next

 public function next()
 {
     $this->valid && $this->index++;
     if ($this->localName) {
         $this->valid = $this->reader->next($this->localName);
     } else {
         $this->valid = $this->reader->next();
     }
 }
开发者ID:hakre,项目名称:xmlreaderiterator,代码行数:9,代码来源:XMLReaderNextIteration.php

示例3: next

 /**
  * @inheritdoc
  */
 public function next()
 {
     if (!isset($this->xmlReader)) {
         throw new \RuntimeException('The resource needs to be open.');
     }
     while ($this->xmlReader->next()) {
         $name = $this->xmlReader->name;
         $depth = $this->xmlReader->depth;
         if (1 == $depth && !in_array($name, array("", "#text"))) {
             break;
         }
     }
 }
开发者ID:yosmanyga,项目名称:resource,代码行数:16,代码来源:XmlFileReader.php

示例4: 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

示例5: 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();
 }
开发者ID:tvart,项目名称:libs,代码行数:29,代码来源:XmlParser.php

示例6: 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

示例7: filterFeed

 /**
  * filterFeed Reads the XML from the url and filters it based on the provided filter. The results are organized into an array keyed by the unqiue values of the filter.
  */
 function filterFeed()
 {
     $reader = new XMLReader();
     if (!$reader->open($this->url)) {
         throw new Exception("Cannot open feed from the provided URL.");
     }
     while ($reader->read()) {
         if ($reader->name == "product") {
             //get the entire product node.
             $xml_node = $reader->readOuterXML();
         }
         if ($reader->name == $this->filter) {
             //read the values for the $this->filter node.
             $reader->read();
             //get string/value from the node we are filtering and explode it by a delimiter.
             $nodeValues = [];
             $nodeValues = explode($this->delimiter, $reader->value);
             if (!empty($nodeValues[$this->index])) {
                 $this->filteredXML[$nodeValues[$this->index]][] = $xml_node;
             } else {
                 throw new Exception("The index specified does not exist.");
             }
             //Go to the next product.
             $reader->next("product");
         }
     }
     //if the array has no items then the filtered node does not exist.
     if (empty($this->filteredXML)) {
         throw new Exception("{$this->filter} does not exist in the XML.");
     }
 }
开发者ID:Gbarnett374,项目名称:xmlfeedparser,代码行数:34,代码来源:feedParserClass.php

示例8: 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();
         }
     }
 }
开发者ID:AhmedNagy,项目名称:tttask,代码行数:18,代码来源:Feed.php

示例9: __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

示例10: testMoveToClosingElement

 /**
  * Tests JFeedParser::moveToClosingElement()
  *
  * @return  void
  *
  * @since   12.3
  */
 public function testMoveToClosingElement()
 {
     // Set the XML for the internal reader and move the stream to the <root> element.
     $this->_reader->Xml('<root><child>foobar</child></root>');
     $this->_reader->next('root');
     // Ensure that the current node is "root".
     $this->assertEquals('root', $this->_reader->name);
     // Move to the closing element, which should be </root>.
     TestReflection::invoke($this->_instance, 'moveToClosingElement');
     $this->assertEquals(XMLReader::END_ELEMENT, $this->_reader->nodeType);
     $this->assertEquals('root', $this->_reader->name);
 }
开发者ID:n3t,项目名称:joomla-cms,代码行数:19,代码来源:JFeedParserTest.php

示例11: 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();
 }
开发者ID:MediaWiki-stable,项目名称:1.26.1,代码行数:20,代码来源:SVGMetadataExtractor.php

示例12: addWikiIndex

 public function addWikiIndex()
 {
     $z = new XMLReader();
     $z->open(self::WIKIFILE);
     // move to the first <page /> node
     while ($z->read() && $z->name !== 'page') {
     }
     $time_start = microtime(true);
     $update = $this->client->createUpdate();
     $i = 0;
     echo "Wait..";
     // now that we're at the right depth, hop to the next <page /> until the end of the tree
     while ($z->name === 'page' && $i++ >= 0) {
         $doct = new DOMDocument();
         // $node = new SimpleXMLElement($z->readOuterXML());
         $node = simplexml_import_dom($doct->importNode($z->expand(), true));
         // now you can use $node without going insane about parsing
         // var_dump($node->element_1);
         if (stristr($node->title, 'Category') === FALSE && stristr($node->revision->text, '#REDIRECT') === FALSE) {
             // echo $node->revision->contributor->id."<br />";
             $doc = $update->createDocument();
             $doc->id = $node->id;
             $doc->title = $node->title;
             $doc->revision = $node->revision->id;
             $doc->author = $node->revision->contributor->username;
             $doc->authorid = $node->revision->contributor->id;
             $doc->timestamp = $node->revision->timestamp;
             $doc->content = $node->revision->text;
             /*
              * if(strlen($node->id)>2) $doc->id = $node->id; else continue; if(strlen($node->title)>2) $doc->title = $node->title; else continue; if(strlen($node->revision->id)>2) $doc->revision = $node->revision->id; else continue; if(strlen($node->revision->timestamp)>2) $doc->timestamp = $node->revision->timestamp; else $doc->timestamp = ""; if(strlen($node->revision->contributor->username)>2) $doc->author = $node->revision->contributor->username; else continue; if(strlen($node->revision->contributor->id)>2) $doc->authorid = $node->revision->contributor->id; else $doc->authorid = " ";
              */
             $update->addDocument($doc);
             if ($i % 1000 == 0) {
                 $update->addCommit();
                 $result = $this->client->update($update);
                 $update = $this->client->createUpdate();
             }
         }
         // go to next <page />
         $z->next('page');
     }
     $time_end = microtime(true);
     // dividing with 60 will give the execution time in minutes other wise seconds
     $execution_time = ($time_end - $time_start) / 60;
     echo '<br /><b>Total Execution Time:</b> ' . $execution_time . ' Mins';
     $update->addCommit();
     $result = $this->client->update($update);
     return View::make('home.index');
 }
开发者ID:amitahire,项目名称:NewsRoom,代码行数:49,代码来源:HomeController.php

示例13: scanContent

 /**
  * Scans conntent for cachedUntil and error
  *   
  * @param string $content
  * @param int $errorCode
  * @param string $errorText
  */
 protected function scanContent($content, &$errorCode, &$errorText)
 {
     $this->cachedUntil = null;
     $reader = new XMLReader();
     $reader->xml($content);
     while ($reader->read()) {
         if ($reader->nodeType == XMLReader::ELEMENT && $reader->name == "error") {
             // got an error
             $errorText = $reader->readString();
             $errorCode = intval($reader->getAttribute('code'));
             if ($reader->next("cachedUntil")) {
                 $this->cachedUntil = $reader->readString();
             }
         } else {
             if ($reader->nodeType == XMLReader::ELEMENT && $reader->name == "result") {
                 // no errors, we need to read the cache time though
                 if ($reader->next("cachedUntil")) {
                     $this->cachedUntil = $reader->readString();
                 }
             }
         }
     }
     $reader->close();
 }
开发者ID:ncrawford,项目名称:eve_contract_viewer,代码行数:31,代码来源:eveonline.php

示例14: insert_data_mysql

 private function insert_data_mysql($db)
 {
     $tbl = $db->query("select sigla, nome from estados");
     $db->query("SET CHARACTER SET utf8");
     $db->query("SET NAMES utf8");
     $tbl->setFetchMode(PDO::FETCH_OBJ);
     while ($row = $tbl->fetch()) {
         // MySQL
         $arr_estados[mb_strtoupper(iconv("ISO-8859-1", "UTF-8", $row->nome), "UTF-8")] = $row->sigla;
         // PostgreSQL
         // $arr_estados[mb_strtoupper($row->nome, "UTF-8")] = $row->sigla;
     }
     var_dump($arr_estados);
     $xml = new XMLReader();
     $xml->open('database/seeds/BR Localidades 2010 v1.kml');
     // Salta as informações de cabeçalho, para o primeiro "registro" de dados ("Placemark")
     while ($xml->read() && $xml->name !== "Placemark") {
     }
     $contador = 0;
     $insert_ok = 0;
     $insert_erro = 0;
     $sql = $db->prepare("insert into cidades(codigo, nome, sigla_estado, longitude, latitude, altitude) values(?, ?, ?, ?, ?, ?)");
     // Loop para varrer todas as ocorrências de "Placemark"
     while ($xml->name === "Placemark") {
         $node = new SimpleXMLElement($xml->readOuterXML());
         $cidade = new SimpleXMLElement($node->asXML());
         $nome = strval($cidade->name);
         // $nome = str_replace("'", "''", $nome);
         $sdata = $cidade->ExtendedData->SchemaData->SimpleData;
         $codigo = intval($sdata[9]);
         $sigla_estado = $arr_estados[strval($sdata[13])];
         $longitude = floatval($sdata[18]);
         $latitude = floatval($sdata[19]);
         $altitude = floatval($sdata[20]);
         $res = $sql->execute(array($codigo, $nome, $sigla_estado, $longitude, $latitude, $altitude));
         if ($res) {
             $insert_ok++;
         } else {
             $insert_erro++;
             echo $nome . " " . $codigo . " " . $sigla_estado . " " . $longitude . " " . $latitude . " " . $altitude . "<br>";
         }
         // Salta para próximo registro
         $xml->next("Placemark");
     }
     echo "Incluiu {$insert_ok} registros com sucesso<br>";
     echo "Falha na inclusão de {$insert_erro} registros<br>";
 }
开发者ID:kwdeveloper,项目名称:crie-app-web,代码行数:47,代码来源:CidadeTableSeeder.php

示例15: 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();
     setSysConfig('geokrety_lastupdate', date($opt['db']['dateformat'], strtotime($startupdate)));
 }
开发者ID:RH-Code,项目名称:opencaching,代码行数:42,代码来源:geokrety.class.php


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