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


PHP XMLReader::read方法代码示例

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


在下文中一共展示了XMLReader::read方法的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: start_process

 public function start_process()
 {
     if (!$this->path_to_xml_file) {
         return false;
     }
     if (!$this->valid_xml) {
         return false;
     }
     $this->archive_builder = new \eol_schema\ContentArchiveBuilder(array('directory_path' => DOC_ROOT . 'temp/xml_to_archive/'));
     $this->taxon_ids = array();
     $this->media_ids = array();
     $this->vernacular_name_ids = array();
     $this->reference_ids = array();
     $this->agent_ids = array();
     $reader = new \XMLReader();
     $file = file_get_contents($this->path_to_xml_file);
     $file = iconv("UTF-8", "UTF-8//IGNORE", $file);
     $reader->XML($file);
     $i = 0;
     while (@$reader->read()) {
         if ($reader->nodeType == \XMLReader::ELEMENT && $reader->name == "taxon") {
             $taxon_xml = $reader->readOuterXML();
             $t = simplexml_load_string($taxon_xml, null, LIBXML_NOCDATA);
             if ($t) {
                 $this->add_taxon_to_archive($t);
             }
             $i++;
             if ($i % 100 == 0) {
                 echo "Parsed taxon {$i} : " . time_elapsed() . "\n";
             }
             // if($i >= 5000) break;
         }
     }
     $this->archive_builder->finalize();
 }
开发者ID:eliagbayani,项目名称:maps_test,代码行数:35,代码来源:XMLToArchive.php

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

示例4: parseNormalError

 /**
  * Most of the error responses are in same format.
  */
 static function parseNormalError(\XMLReader $xmlReader)
 {
     $result = array('Code' => NULL, 'Message' => NULL, 'RequestId' => NULL, 'HostId' => NULL);
     while ($xmlReader->Read()) {
         if ($xmlReader->nodeType == \XMLReader::ELEMENT) {
             switch ($xmlReader->name) {
                 case 'Code':
                     $xmlReader->read();
                     if ($xmlReader->nodeType == \XMLReader::TEXT) {
                         $result['Code'] = $xmlReader->value;
                     }
                     break;
                 case 'Message':
                     $xmlReader->read();
                     if ($xmlReader->nodeType == \XMLReader::TEXT) {
                         $result['Message'] = $xmlReader->value;
                     }
                     break;
                 case 'RequestId':
                     $xmlReader->read();
                     if ($xmlReader->nodeType == \XMLReader::TEXT) {
                         $result['RequestId'] = $xmlReader->value;
                     }
                     break;
                 case 'HostId':
                     $xmlReader->read();
                     if ($xmlReader->nodeType == \XMLReader::TEXT) {
                         $result['HostId'] = $xmlReader->value;
                     }
                     break;
             }
         }
     }
     return $result;
 }
开发者ID:lizhengqiang,项目名称:thinkphp,代码行数:38,代码来源:XMLParser.php

示例5: generateAcronymInfo

 public static function generateAcronymInfo($filename)
 {
     static $info;
     if ($info) {
         return $info;
     }
     $r = new \XMLReader();
     if (!$r->open($filename)) {
         throw new \Exception("Could not open file for accessing acronym information:  {$filename}");
     }
     $acronyms = array();
     while ($r->read()) {
         if ($r->nodeType != \XMLReader::ELEMENT) {
             continue;
         }
         if ($r->name == "term") {
             $r->read();
             $k = $r->value;
             $acronyms[$k] = "";
         } else {
             if ($r->name == "simpara") {
                 $r->read();
                 $acronyms[$k] = $r->value;
             }
         }
     }
     $info = $acronyms;
     return $acronyms;
 }
开发者ID:philip,项目名称:phd,代码行数:29,代码来源:XHTML.php

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

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

示例8: rewind

 public function rewind()
 {
     if ($this->reader->nodeType !== XMLReader::NONE) {
         throw new BadMethodCallException('Reader can not be rewound');
     }
     $this->index = 0;
     $this->valid = $this->reader->read();
 }
开发者ID:ExpandOnline,项目名称:XMLReaderIterator,代码行数:8,代码来源:XMLReaderIteration.php

示例9: parse

 protected function parse()
 {
     $depth = 0;
     $elements = array();
     $elements_[$depth] =& $elements;
     while ($this->xml->read()) {
         switch ($this->xml->nodeType) {
             case XMLReader::END_ELEMENT:
                 if ($this->xml->depth - 1 < $depth) {
                     $elements =& $elements_[$depth];
                     $element =& $elements[sizeof($elements) - 1];
                     $depth = $this->xml->depth - 1;
                 }
                 break;
             case XMLReader::ATTRIBUTE:
                 # Read does not go through attributes :(
                 break;
             case XMLReader::ELEMENT:
                 if (strlen($this->xml->name) == 0) {
                     continue;
                 }
                 if ($this->xml->depth > $depth) {
                     $depth = $this->xml->depth;
                     $elements_[$depth] =& $elements;
                     $elements =& $element['elements'];
                 }
                 $elements[] = array('tag' => $this->xml->name);
                 # Working Element
                 $element =& $elements[sizeof($elements) - 1];
                 # Attributes
                 if ($this->xml->hasAttributes) {
                     $this->xml->moveToFirstAttribute();
                     $element['attributes'] = array();
                     $element['attributes'][$this->xml->name] = $this->xml->value;
                     while ($this->xml->moveToNextAttribute()) {
                         $element['attributes'][$this->xml->name] = $this->xml->value;
                     }
                 }
                 if ($this->xml->isEmptyElement) {
                     if ($this->xml->depth - 1 < $depth) {
                         $elements =& $elements_[$depth];
                         $element =& $elements[sizeof($elements) - 1];
                         $depth = $this->xml->depth - 1;
                     }
                 }
                 break;
             case XMLReader::TEXT:
             case XMLReader::CDATA:
                 if (!isset($element['value'])) {
                     $element['value'] = $this->xml->value;
                 } else {
                     $element['value'] .= $this->xml->value;
                 }
                 break;
         }
     }
     $this->elements = $elements;
 }
开发者ID:joksnet,项目名称:php-old,代码行数:58,代码来源:Reader.php

示例10: rewind

 /**
  * @return void
  */
 public function rewind()
 {
     $this->reader->open($this->file, 'utf-8', defined('LIBXML_COMPACT') ? constant('LIBXML_COMPACT') : 0);
     while ($this->reader->read()) {
         if ($this->valid()) {
             break;
         }
     }
 }
开发者ID:KalanaPerera,项目名称:cufon,代码行数:12,代码来源:SVGFontContainer.php

示例11: processXml

/**
 * Process the XML query
 * @param $xmltext the provided XML
 */
function processXml($xmltext)
{
    // Load the XML
    $xml = new XMLReader();
    if (!$xml->XML($xmltext)) {
        echo '<hatter status="no" msg="invalid XML" />';
        exit;
    }
    // Connect to the database
    $pdo = pdo_connect();
    // Read to the start tag
    while ($xml->read()) {
        if ($xml->nodeType == XMLReader::ELEMENT && $xml->name == "hatter") {
            // We have the hatter tag
            $magic = $xml->getAttribute("magic");
            if ($magic != "NechAtHa6RuzeR8x") {
                echo '<hatter status="no" msg="magic" />';
                exit;
            }
            $user = $xml->getAttribute("user");
            $password = $xml->getAttribute("pw");
            $userid = getUser($pdo, $user, $password);
            // Read to the hatting tag
            while ($xml->read()) {
                if ($xml->nodeType == XMLReader::ELEMENT && $xml->name == "hatting") {
                    $name = $xml->getAttribute("name");
                    $uri = $xml->getAttribute("uri");
                    $x = $xml->getAttribute("x");
                    $y = $xml->getAttribute("y");
                    $angle = $xml->getAttribute("angle");
                    $scale = $xml->getAttribute("scale");
                    $color = $xml->getAttribute("color");
                    $hat = $xml->getAttribute("hat");
                    $feather = $xml->getAttribute("feather") == "yes" ? 1 : 0;
                    $nameQ = $pdo->quote($name);
                    $uriQ = $pdo->quote($uri);
                    // Checks
                    if (!is_numeric($x) || !is_numeric($y) || !is_numeric($angle) || !is_numeric($scale) || !is_numeric($color) || !is_numeric($hat)) {
                        echo '<hatter status="no" msg="invalid" />';
                        exit;
                    }
                    $query = <<<QUERY
REPLACE INTO hatting(name, userid, uri, type, x, y, rotation, scale, color, feather)
VALUES({$nameQ}, '{$userid}', {$uriQ}, {$hat}, {$x}, {$y}, {$angle}, {$scale}, {$color}, {$feather})
QUERY;
                    if (!$pdo->query($query)) {
                        echo '<hatter status="no" msg="insertfail">' . $query . '</hatter>';
                        exit;
                    }
                    echo '<hatter status="yes"/>';
                    exit;
                }
            }
        }
    }
    echo '<hatter save="no" msg="invalid XML" />';
}
开发者ID:Jallal,项目名称:iOS-IndoorMaps,代码行数:61,代码来源:hatter-save.php

示例12: parseInfo

 protected function parseInfo(\XMLReader $xml, InfosAbstract $object)
 {
     // we don't read the name attribute for the module name as in previous jelix version, it has always to be the directory name
     if ($object->type == 'application') {
         $object->name = (string) $xml->getAttribute('name');
     }
     $object->createDate = (string) $xml->getAttribute('createdate');
     $locale = array('label' => $this->locale, 'description' => $this->locale);
     while ($xml->read()) {
         if (\XMLReader::END_ELEMENT == $xml->nodeType && 'info' == $xml->name) {
             break;
         }
         if ($xml->nodeType == \XMLReader::ELEMENT) {
             $property = $xml->name;
             if ('label' == $property || 'description' == $property) {
                 if ($xml->getAttribute('lang') == $locale[$property] || $locale[$property] == '') {
                     $xml->read();
                     $object->{$property} = $xml->value;
                     if ($locale[$property] == '') {
                         // let's mark we readed the element corresponding to the locale
                         $locale[$property] = '__readed__';
                     }
                 }
             } elseif ('author' == $property || 'creator' == $property || 'contributor' == $property) {
                 $person = array();
                 while ($xml->moveToNextAttribute()) {
                     $attrName = $xml->name;
                     $person[$attrName] = $xml->value;
                 }
                 array_push($object->authors, $person);
             } elseif ('licence' == $property) {
                 // we support licence and license, but store always as license
                 while ($xml->moveToNextAttribute()) {
                     $attrProperty = 'license' . ucfirst($xml->name);
                     $object->{$attrProperty} = $xml->value;
                 }
                 $xml->read();
                 $object->license = $xml->value;
             } else {
                 // <version> <license> <copyright> <homepageURL> <updateURL>
                 // read attributes 'date', 'stability' etc ... and store them into versionDate, versionStability
                 while ($xml->moveToNextAttribute()) {
                     $attrProperty = $property . ucfirst($xml->name);
                     $object->{$attrProperty} = $xml->value;
                 }
                 $xml->read();
                 if ($property == 'version') {
                     $object->{$property} = $this->fixVersion($xml->value);
                 } else {
                     $object->{$property} = $xml->value;
                 }
             }
         }
     }
     return $object;
 }
开发者ID:mdouchin,项目名称:jelix,代码行数:56,代码来源:XmlParserAbstract.php

示例13: main

function main()
{
    var_dump(stream_wrapper_register('strstream', 'StringWrapper'));
    $r = new XMLReader();
    $r->open("strstream://");
    var_dump($r->read());
    var_dump($r->readOuterXML());
    var_dump($r->readInnerXML());
    var_dump($r->read());
    var_dump($r->readOuterXML());
    var_dump($r->readInnerXML());
}
开发者ID:badlamer,项目名称:hhvm,代码行数:12,代码来源:xmlreader_user_stream.php

示例14: rewind

 /**
  * {@inheritdoc}
  */
 public function rewind()
 {
     $this->position = 0;
     $this->reader = new XMLReader();
     $this->reader->open($this->file);
     $this->reader->read();
     $this->reader->next();
     $this->reader->read();
     $this->reader->next();
     $this->reader->next();
     while ($this->reader->read() && $this->reader->name !== 'product') {
     }
 }
开发者ID:vecbralis,项目名称:magento-nedis-import,代码行数:16,代码来源:CatalogReader.php

示例15: getRows

 public function getRows($maxCount = 1000)
 {
     $this->ensureMaxCountIsValid($maxCount);
     $result = [];
     $count = 0;
     while ($count < $maxCount && $this->reader->read()) {
         if ($this->checkIsNodeAccepted($this->reader->name)) {
             $result[] = $this->getRowAttributes();
             ++$count;
         }
     }
     return $result;
 }
开发者ID:apolev,项目名称:fias,代码行数:13,代码来源:XmlReader.php


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