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


PHP XMLReader::open方法代码示例

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


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

示例1: 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();
 }
开发者ID:treehouselabs,项目名称:io-bundle,代码行数:36,代码来源:ExportValidateCommand.php

示例2: open

 /**
  * Open a file process.
  *
  * @param  string  $file
  * @return boolean
  */
 public function open($file)
 {
     if (!file_exists($file)) {
         throw new Exception(sprintf('Unable to open file %s', $file));
     }
     return $this->process->open($file);
 }
开发者ID:pandaac,项目名称:exporter,代码行数:13,代码来源:Reader.php

示例3: open

 private function open()
 {
     if (!$this->reader) {
         $this->reader = new \XMLReader();
         $this->reader->open($this->xmlFilePath);
     }
 }
开发者ID:rhubarbphp,项目名称:rhubarb,代码行数:7,代码来源:XmlParser.php

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

示例5: __construct

 /**
  *  Instantiate our GPX handler, and load the specified filename
  *
  *  @param   string  $gpxFilename  Load the specified filename into our GPX handler
  *  @throws  \Exception  Unable to load the specified file
  **/
 public function __construct($gpxFilename)
 {
     if (!file_exists($gpxFilename)) {
         throw new \Exception(sprintf('File "%s" does not exist', $gpxFilename));
     }
     $this->gpxReader = new \XMLReader();
     $this->gpxReader->open($gpxFilename);
 }
开发者ID:MarkBaker,项目名称:GeneratorFunctionExamples,代码行数:14,代码来源:GpxHandler.php

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

示例7: initializeReader

 private function initializeReader($pathToFile)
 {
     FileHelper::ensureIsReadable($pathToFile);
     $this->reader = new \XMLReader();
     $success = $this->reader->open($pathToFile);
     if (!$success) {
         throw new ImporterException('Ошибка открытия XML файла по адресу: ' . $pathToFile);
     }
 }
开发者ID:apolev,项目名称:fias,代码行数:9,代码来源:XmlReader.php

示例8: __construct

 /**
  * @param string $xml
  */
 public function __construct($xml)
 {
     $this->xml = new XMLReader();
     if (preg_match('/^<\\?xml/', trim($xml))) {
         $this->xml->XML($xml);
     } else {
         $this->xml->open($xml);
     }
     $this->parse();
 }
开发者ID:joksnet,项目名称:php-old,代码行数:13,代码来源:Reader.php

示例9: XMLReader

 /**
  * Constructor
  *
  * Creates an SVGReader drawing from the source provided
  * @param string $source URI from which to read
  * @throws MWException|Exception
  */
 function __construct($source)
 {
     global $wgSVGMetadataCutoff;
     $this->reader = new XMLReader();
     // Don't use $file->getSize() since file object passed to SVGHandler::getMetadata is bogus.
     $size = filesize($source);
     if ($size === false) {
         throw new MWException("Error getting filesize of SVG.");
     }
     if ($size > $wgSVGMetadataCutoff) {
         $this->debug("SVG is {$size} bytes, which is bigger than {$wgSVGMetadataCutoff}. Truncating.");
         $contents = file_get_contents($source, false, null, -1, $wgSVGMetadataCutoff);
         if ($contents === false) {
             throw new MWException('Error reading SVG file.');
         }
         $this->reader->XML($contents, null, LIBXML_NOERROR | LIBXML_NOWARNING);
     } else {
         $this->reader->open($source, null, LIBXML_NOERROR | LIBXML_NOWARNING);
     }
     // Expand entities, since Adobe Illustrator uses them for xmlns
     // attributes (bug 31719). Note that libxml2 has some protection
     // against large recursive entity expansions so this is not as
     // insecure as it might appear to be. However, it is still extremely
     // insecure. It's necessary to wrap any read() calls with
     // libxml_disable_entity_loader() to avoid arbitrary local file
     // inclusion, or even arbitrary code execution if the expect
     // extension is installed (bug 46859).
     $oldDisable = libxml_disable_entity_loader(true);
     $this->reader->setParserProperty(XMLReader::SUBST_ENTITIES, true);
     $this->metadata['width'] = self::DEFAULT_WIDTH;
     $this->metadata['height'] = self::DEFAULT_HEIGHT;
     // The size in the units specified by the SVG file
     // (for the metadata box)
     // Per the SVG spec, if unspecified, default to '100%'
     $this->metadata['originalWidth'] = '100%';
     $this->metadata['originalHeight'] = '100%';
     // Because we cut off the end of the svg making an invalid one. Complicated
     // try catch thing to make sure warnings get restored. Seems like there should
     // be a better way.
     MediaWiki\suppressWarnings();
     try {
         $this->read();
     } catch (Exception $e) {
         // Note, if this happens, the width/height will be taken to be 0x0.
         // Should we consider it the default 512x512 instead?
         MediaWiki\restoreWarnings();
         libxml_disable_entity_loader($oldDisable);
         throw $e;
     }
     MediaWiki\restoreWarnings();
     libxml_disable_entity_loader($oldDisable);
 }
开发者ID:MediaWiki-stable,项目名称:1.26.1,代码行数:59,代码来源:SVGMetadataExtractor.php

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

示例11: __construct

 public function __construct($inFile)
 {
     $this->_reader = new XMLReader();
     $this->_reader->open($inFile);
     $this->_reader->read();
     // Check that we are in the right place
     while ($this->_reader->read()) {
         if ($this->_reader->nodeType == XMLReader::ELEMENT) {
             break;
         }
     }
     if (!($this->_reader->nodeType == XMLReader::ELEMENT && $this->_reader->name == 'roboml_toc')) {
         throw new ErrorException("Unexpected XML node: {$this->_reader->name}");
     }
 }
开发者ID:shevron,项目名称:HumanHelp,代码行数:15,代码来源:robohelp-xhtml-import.php

示例12: actionFias

 public function actionFias()
 {
     $file = 'AS_ADDROBJ_20160609_c5080ba4-9f46-4b6e-aecc-72a630730b3a.XML';
     $interestingNodes = array('AOGUID');
     $xmlObject = new \XMLReader();
     $xmlObject->open($file);
     header('Content-Type: text/html; charset=utf-8');
     $i = 0;
     while ($xmlObject->read()) {
         if ($xmlObject->name == 'Object') {
             if ($xmlObject->getAttribute('IFNSFL') == '8603') {
                 // if (($xmlObject->getAttribute('PARENTGUID') == '0bf0f4ed-13f8-446e-82f6-325498808076' && $xmlObject->getAttribute('AOLEVEL') == '7') || $xmlObject->getAttribute('AOGUID') == '0bf0f4ed-13f8-446e-82f6-325498808076') {
                 $fias = new Fias();
                 $fias->AOGUID = $xmlObject->getAttribute('AOGUID');
                 $fias->OFFNAME = $xmlObject->getAttribute('OFFNAME');
                 $fias->SHORTNAME = $xmlObject->getAttribute('SHORTNAME');
                 $fias->IFNSFL = $xmlObject->getAttribute('IFNSFL');
                 $fias->AOLEVEL = $xmlObject->getAttribute('AOLEVEL');
                 $fias->PARENTGUID = $xmlObject->getAttribute('PARENTGUID');
                 if ($fias->validate()) {
                     $fias->save();
                 } else {
                     var_dump($fias->attributes);
                     var_dump($fias->getErrors());
                 }
                 //    $i++;
             }
         }
     }
     echo 'ok';
     $xmlObject->close();
 }
开发者ID:vovancho,项目名称:yii2test,代码行数:32,代码来源:FregatController.php

示例13: getFeed

 /**
  * Method to load a URI into the feed reader for parsing.
  *
  * @param   string  $uri  The URI of the feed to load. Idn uris must be passed already converted to punycode.
  *
  * @return  JFeedReader
  *
  * @since   12.3
  * @throws  InvalidArgumentException
  * @throws  RuntimeException
  */
 public function getFeed($uri)
 {
     // Create the XMLReader object.
     $reader = new XMLReader();
     // Open the URI within the stream reader.
     if (!@$reader->open($uri, null, LIBXML_NOERROR | LIBXML_ERR_NONE | LIBXML_NOWARNING)) {
         // Retry with JHttpFactory that allow using CURL and Sockets as alternative method when available
         // Adding a valid user agent string, otherwise some feed-servers returning an error
         $options = new \joomla\Registry\Registry();
         $options->set('userAgent', 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:41.0) Gecko/20100101 Firefox/41.0');
         $connector = JHttpFactory::getHttp($options);
         $feed = $connector->get($uri);
         if ($feed->code != 200) {
             throw new RuntimeException('Unable to open the feed.');
         }
         // Set the value to the XMLReader parser
         if (!$reader->xml($feed->body, null, LIBXML_NOERROR | LIBXML_ERR_NONE | LIBXML_NOWARNING)) {
             throw new RuntimeException('Unable to parse the feed.');
         }
     }
     try {
         // Skip ahead to the root node.
         while ($reader->read()) {
             if ($reader->nodeType == XMLReader::ELEMENT) {
                 break;
             }
         }
     } catch (Exception $e) {
         throw new RuntimeException('Error reading feed.', $e->getCode(), $e);
     }
     // Setup the appopriate feed parser for the feed.
     $parser = $this->_fetchFeedParser($reader->name, $reader);
     return $parser->parse();
 }
开发者ID:adjaika,项目名称:J3Base,代码行数:45,代码来源:factory.php

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

示例15: xsl

 function xsl()
 {
     $this->data['title'] = 'Trends XSL';
     $this->data['pagebody'] = 'vtrendsxsl';
     //obtains view template data
     $this->load->helper('display');
     //loads the helper functionality
     $this->data['myxml'] = display_file('./data/xml/energy.xml');
     //displays the contents of the xml file in the myxml placeholder
     $this->data['xmltable'] = xsl_transform('./data/xml/energy.xml', './data/xml/energy.xsl');
     $this->data['eproduced'] = xsl_transform('./data/xml/energy.xml', './data/xml/energy2.xsl');
     $this->data['eused'] = xsl_transform('./data/xml/energy.xml', './data/xml/energy3.xsl');
     $doc = new DOMDocument();
     //$doc->validateOnParse = true;
     $doc->load('./data/xml/energy.xml');
     $xml = XMLReader::open('./data/xml/energy.xml');
     $xml->setSchema('./data/xml/energy.xsd');
     // You must to use it
     $xml->setParserProperty(XMLReader::VALIDATE, true);
     libxml_use_internal_errors(true);
     if ($xml->isValid()) {
         $this->data['validatedxml'] = '<br/>XML Valid <br/><br/>';
     } else {
         $result = "<b>ERROR</b><br/>";
         foreach (libxml_get_errors() as $error) {
             $result .= $error->message . '<br/>';
         }
         libxml_clear_errors();
         $result .= '<br/>';
         $this->data['validatedxml'] = $result;
     }
     $this->render();
     //renders the page
 }
开发者ID:kptnkrnch,项目名称:COMP-4711-Final-Project,代码行数:34,代码来源:trends.php


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