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


PHP XMLReader::setParserProperty方法代码示例

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


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

function isXml($filename)
{
    $xml = new XMLReader();
    $xml->open($filename);
    $xml->setParserProperty(XMLReader::VALIDATE, true);
    return $xml->isValid();
}
开发者ID:eustasy,项目名称:normal-checks,代码行数:7,代码来源:xml.php

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

示例4: 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;
 }
开发者ID:VitProg,项目名称:nas-test-app,代码行数:45,代码来源:CurrencySourceBase.php

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

示例6: validateFromInput

 /**
  * @param string $fname the filename
  */
 private function validateFromInput($xml, $isFile)
 {
     $reader = new XMLReader();
     if ($isFile) {
         $s = $reader->open($xml, null, LIBXML_NOERROR | LIBXML_NOWARNING);
     } else {
         $s = $reader->XML($xml, null, LIBXML_NOERROR | LIBXML_NOWARNING);
     }
     if ($s !== true) {
         // Couldn't open the XML
         $this->wellFormed = false;
     } else {
         $oldDisable = libxml_disable_entity_loader(true);
         $reader->setParserProperty(XMLReader::SUBST_ENTITIES, true);
         try {
             $this->validate($reader);
         } catch (Exception $e) {
             // Calling this malformed, because we didn't parse the whole
             // thing. Maybe just an external entity refernce.
             $this->wellFormed = false;
             $reader->close();
             libxml_disable_entity_loader($oldDisable);
             throw $e;
         }
         $reader->close();
         libxml_disable_entity_loader($oldDisable);
     }
 }
开发者ID:claudinec,项目名称:galan-wiki,代码行数:31,代码来源:XmlTypeCheck.php

示例7: updateL10N

 public function updateL10N()
 {
     //echo $this->html;
     // PHASE1: Convert span-level elements
     $depth = 1;
     $text = "";
     echo $this->filename;
     $src = "<html>" . $this->html . "</html>";
     /* Drop stupid ms-word quotes */
     $src = str_replace("‘", "'", $src);
     $src = str_replace("’", "'", $src);
     $extractmode = true;
     $tf = new LinkORB_TranslationFile();
     $tf->name = "markdown-topic:" . $this->filename;
     $tf->datatype = "x-linkorb-markdown-topic";
     $tf->sourcelang = "en_US";
     $tf->targetlang = "en_US";
     $tf->tool = "x-lt-ldoc-updatel10n";
     $l10npath = dirname($this->filename) . "/l10n/";
     if (!file_exists($l10npath)) {
         mkdir($l10npath);
     }
     // Load previous trans-unit's if available
     if (file_exists($l10npath . basename($this->filename) . ".src.xlf")) {
         $tf->LoadXLIFF($l10npath . basename($this->filename) . ".src.xlf", true);
         // Set all transunit's to 'translate=false'
         foreach ($tf->transunit as $tu) {
             $tu->translate = "no";
             $tu->comment = array();
             $tu->filename = array();
         }
     }
     $xhtml = new XMLReader();
     $xhtml->setParserProperty('SUBST_ENTITIES', 0);
     $xhtml->xml($src);
     $skiptext = false;
     $inpre = false;
     while ($xhtml->read() && $depth != 0) {
         if (in_array($xhtml->nodeType, array(XMLReader::TEXT, XMLReader::CDATA, XMLReader::WHITESPACE, XMLReader::SIGNIFICANT_WHITESPACE))) {
             if (!$skiptext) {
                 //$text .= htmlentities($xhtml->value); // Leaving entities as-is now
                 $text .= $xhtml->value;
             }
         }
         // OPENING TAG
         if ($xhtml->nodeType == XMLReader::ELEMENT) {
             switch ($xhtml->name) {
                 case "code":
                     if (!$inpre) {
                         $text .= "`";
                     }
                     break;
                 case "pre":
                     $inpre = true;
                     $text .= "<" . $xhtml->name . ">";
                     break;
                 case "em":
                     $text .= "*";
                     break;
                 case "a":
                     $text .= "[linktext](http://www.example.com)";
                     $skiptext = true;
                     break;
                 default:
                     $text .= "<" . $xhtml->name . ">";
                     break;
             }
             $depth++;
         }
         // CLOSING TAG
         if ($xhtml->nodeType == XMLReader::END_ELEMENT) {
             switch ($xhtml->name) {
                 case "code":
                     if (!$inpre) {
                         $text .= "`";
                     }
                     break;
                 case "pre":
                     $inpre = false;
                     $text .= "</" . $xhtml->name . ">";
                     break;
                 case "em":
                     $text .= "*";
                     break;
                 case "a":
                     $text .= "";
                     $skiptext = false;
                     break;
                 default:
                     $text .= "</" . $xhtml->name . ">";
                     break;
             }
             $depth--;
         }
     }
     // PHASE2: Convert block-level elements
     $depth = 1;
     $xhtml = new XMLReader();
     $text = str_replace("<br>", "<br />", $text);
     $xhtml->xml($text);
//.........这里部分代码省略.........
开发者ID:doxedo,项目名称:core,代码行数:101,代码来源:L10n.php

示例8: validateFile

 private function validateFile($file_name)
 {
     $extension = pathinfo($file_name, PATHINFO_EXTENSION);
     $file_info = explode(".", $file_name);
     $file_info1 = explode("_", $file_info[0]);
     $file_id = $file_info1[1];
     // verificam validitatea fisierului in fctie de extensie
     if ($extension == "xml") {
         $reader = new XMLReader();
         $reader->open(DIR_FILE_FOR_MATCHING . $file_name);
         // Set parser options - you must set this in order to use isValid method
         $reader->setParserProperty(XMLReader::VALIDATE, TRUE);
         $a = 0;
         if (!$reader->isValid()) {
             // se sterge din baza de date si de pe server
             $this->model_account_customer_file_for_matching->deleteFile($file_id);
             $this->session->data['warning'] = $this->language->get('text_xml_file_is_not_valid');
             return false;
         } else {
             // in cazul in care xml-ul este valid, verificam daca contine datele obligatorii specificate webservice-ului
             $xml = simplexml_load_file(DIR_FILE_FOR_MATCHING . $file_name);
             foreach ($xml->children()->children() as $child) {
                 $this->xml_node[] = strtoupper(trim($child->getName()));
             }
             $xml_valid = 1;
             foreach ($this->mandatory_data as $value) {
                 if (!in_array($value, $this->xml_node)) {
                     $xml_valid = 0;
                     break;
                 }
             }
             if ($xml_valid == 0) {
                 // se sterge din baza de date si de pe server
                 $this->model_account_customer_file_for_matching->deleteFile($file_id);
                 $this->session->data['warning'] = $this->language->get('text_xml_file_not_contain_mandatory_data');
                 return false;
             } else {
                 return true;
             }
         }
     } else {
         if ($extension == "csv") {
             $csv_delimiter = $this->model_account_customer_file_for_matching->getCsvDelimiter($file_id);
             $filerow = array();
             $filerow = @file(DIR_FILE_FOR_MATCHING . $file_name);
             $csv_header = explode($csv_delimiter, $filerow[0]);
             $csv_have_header = 1;
             // verificam daca fisierul csv are header
             foreach ($csv_header as $value) {
                 if (is_numeric(trim($value))) {
                     // se sterge din baza de date si de pe server
                     $this->model_account_customer_file_for_matching->deleteFile($file_id);
                     $this->session->data['warning'] = $this->language->get('text_csv_file_without_header');
                     return false;
                 }
             }
             // transformam in litere mari
             $header = array();
             foreach ($csv_header as $value) {
                 $header[] = strtoupper(trim($value));
             }
             // in cazul in care csv -ul are header, verificam daca headerul contine datele obligatorii specificate webservice-ului
             foreach ($this->mandatory_data as $value) {
                 if (!in_array($value, $header)) {
                     $csv_have_header = 0;
                     break;
                 }
             }
             if ($csv_have_header == 0) {
                 // se sterge din baza de date si de pe server
                 $this->model_account_customer_file_for_matching->deleteFile($file_id);
                 $this->session->data['warning'] = $this->language->get('text_csv_file_not_contain_mandatory_data');
                 return false;
             } else {
                 return true;
             }
         }
     }
 }
开发者ID:bgabor,项目名称:RenaniaOpencart,代码行数:79,代码来源:matchclientdata.php

示例9: listWorksheetInfo

 /**
  * Return worksheet info (Name, Last Column Letter, Last Column Index, Total Rows, Total Columns)
  *
  * @param   string     $pFilename
  * @throws   PHPExcel_Reader_Exception
  */
 public function listWorksheetInfo($pFilename)
 {
     // Check if file exists
     if (!file_exists($pFilename)) {
         throw new PHPExcel_Reader_Exception("Could not open " . $pFilename . " for reading! File does not exist.");
     }
     $xml = new XMLReader();
     $xml->open('compress.zlib://' . realpath($pFilename));
     $xml->setParserProperty(2, true);
     $worksheetInfo = array();
     while ($xml->read()) {
         if ($xml->name == 'gnm:Sheet' && $xml->nodeType == XMLReader::ELEMENT) {
             $tmpInfo = array('worksheetName' => '', 'lastColumnLetter' => 'A', 'lastColumnIndex' => 0, 'totalRows' => 0, 'totalColumns' => 0);
             while ($xml->read()) {
                 if ($xml->name == 'gnm:Name' && $xml->nodeType == XMLReader::ELEMENT) {
                     $xml->read();
                     //	Move onto the value node
                     $tmpInfo['worksheetName'] = (string) $xml->value;
                 } elseif ($xml->name == 'gnm:MaxCol' && $xml->nodeType == XMLReader::ELEMENT) {
                     $xml->read();
                     //	Move onto the value node
                     $tmpInfo['lastColumnIndex'] = (int) $xml->value;
                     $tmpInfo['totalColumns'] = (int) $xml->value + 1;
                 } elseif ($xml->name == 'gnm:MaxRow' && $xml->nodeType == XMLReader::ELEMENT) {
                     $xml->read();
                     //	Move onto the value node
                     $tmpInfo['totalRows'] = (int) $xml->value + 1;
                     break;
                 }
             }
             $tmpInfo['lastColumnLetter'] = PHPExcel_Cell::stringFromColumnIndex($tmpInfo['lastColumnIndex']);
             $worksheetInfo[] = $tmpInfo;
         }
     }
     return $worksheetInfo;
 }
开发者ID:AlexandreSGV,项目名称:siteentec,代码行数:42,代码来源:Gnumeric.php

示例10: checkParseSafety

 /**
  * Check if a block of XML is safe to pass to xml_parse, i.e. doesn't
  * contain a doctype declaration which could contain a dos attack if we
  * parse it and expand internal entities (T85848).
  *
  * @param string $content xml string to check for parse safety
  * @return bool true if the xml is safe to parse, false otherwise
  */
 private function checkParseSafety($content)
 {
     $reader = new XMLReader();
     $result = null;
     // For XMLReader to parse incomplete/invalid XML, it has to be open()'ed
     // instead of using XML().
     $reader->open('data://text/plain,' . urlencode($content), null, LIBXML_NOERROR | LIBXML_NOWARNING | LIBXML_NONET);
     $oldDisable = libxml_disable_entity_loader(true);
     /** @noinspection PhpUnusedLocalVariableInspection */
     $reset = new ScopedCallback('libxml_disable_entity_loader', array($oldDisable));
     $reader->setParserProperty(XMLReader::SUBST_ENTITIES, false);
     // Even with LIBXML_NOWARNING set, XMLReader::read gives a warning
     // when parsing truncated XML, which causes unit tests to fail.
     MediaWiki\suppressWarnings();
     while ($reader->read()) {
         if ($reader->nodeType === XMLReader::ELEMENT) {
             // Reached the first element without hitting a doctype declaration
             $this->parsable = self::PARSABLE_OK;
             $result = true;
             break;
         }
         if ($reader->nodeType === XMLReader::DOC_TYPE) {
             $this->parsable = self::PARSABLE_NO;
             $result = false;
             break;
         }
     }
     MediaWiki\restoreWarnings();
     if (!is_null($result)) {
         return $result;
     }
     // Reached the end of the parsable xml without finding an element
     // or doctype. Buffer and try again.
     $this->parsable = self::PARSABLE_BUFFERING;
     $this->xmlParsableBuffer = $content;
     return false;
 }
开发者ID:ngertrudiz,项目名称:mediawiki,代码行数:45,代码来源:XMP.php

示例11: testScrape

 public function testScrape()
 {
     $parser = new \Seld\JsonLint\JsonParser();
     $googleScraper = Builder::create($this->engines[0], array(array('foo', 'baz'), 'google'));
     $outDir = $googleScraper->getOutDir();
     $this->assertFalse($googleScraper->scrape('bar'));
     $this->assertFalse($googleScraper->scrape('baz', 100));
     $this->assertFalse($googleScraper->scrape('baz', 1, 'baz'));
     $this->assertFalse($googleScraper->scrape('baz', 1, true, 'foobad'));
     $this->assertFalse($googleScraper->scrape('baz', 1, true, 'UTC', 'faz'));
     $this->assertFalse($googleScraper->serialize('json'));
     $this->assertTrue($googleScraper->scrape('foo', 2, true, 'Europe/Berlin'));
     $this->assertCount(2, $googleScraper->getFetchedPages());
     $this->assertCount(1, $googleScraper->getKeywords());
     $this->assertTrue($googleScraper->scrape('baz', 2, true));
     $this->assertCount(4, $googleScraper->getFetchedPages());
     $this->assertCount(0, $googleScraper->getKeywords());
     $this->assertFalse($googleScraper->scrapeAll());
     $this->assertTrue($googleScraper->addKeywords(array('foobaz', 'foobar')));
     $this->assertTrue($googleScraper->scrapeAll(2, true, 'America/Los_Angeles'));
     $this->assertCount(8, $googleScraper->getFetchedPages());
     $this->assertCount(0, $googleScraper->getKeywords());
     $this->assertFalse($googleScraper->serialize('baz'));
     $this->assertTrue($googleScraper->serialize('json', true));
     $this->assertCount(0, $googleScraper->getFetchedPages());
     $this->assertCount(8, $googleScraper->getSerializedPages());
     $toCheck = array_map('Franzip\\SerpScraper\\Helpers\\FileSystemHelper::generateFileName', array_keys($googleScraper->getSerializedPages()));
     $this->assertTrue($googleScraper->save(true));
     for ($i = 0; $i < count($toCheck); $i++) {
         $json = file_get_contents($outDir . DIRECTORY_SEPARATOR . $toCheck[$i]);
         $this->assertNull($parser->lint($json));
     }
     $this->assertTrue($googleScraper->addKeywords(array('foo bad')));
     $this->assertTrue($googleScraper->scrapeAll(3, true));
     $this->assertCount(3, $googleScraper->getFetchedPages());
     $this->assertTrue($googleScraper->serialize('xml', true));
     $this->assertCount(0, $googleScraper->getFetchedPages());
     $this->assertCount(3, $googleScraper->getSerializedPages());
     $toCheck = array_map('Franzip\\SerpScraper\\Helpers\\FileSystemHelper::generateFileName', array_keys($googleScraper->getSerializedPages()));
     $this->assertTrue($googleScraper->save(true));
     for ($i = 0; $i < count($toCheck); $i++) {
         $xml = new \XMLReader();
         $xml->open($outDir . DIRECTORY_SEPARATOR . $toCheck[$i]);
         $xml->setParserProperty(\XMLReader::VALIDATE, true);
         $this->assertTrue($xml->isValid());
     }
     $askScraper = Builder::create($this->engines[1], array(array('foo', 'baz'), 'ask'));
     $outDir = $askScraper->getOutDir();
     $this->assertFalse($askScraper->scrape('bar'));
     $this->assertFalse($askScraper->scrape('baz', 100));
     $this->assertFalse($askScraper->scrape('baz', 1, 'baz'));
     $this->assertFalse($askScraper->scrape('baz', 1, true, 'foobad'));
     $this->assertFalse($askScraper->scrape('baz', 1, true, 'UTC', 'faz'));
     $this->assertTrue($askScraper->scrape('foo', 2, true, 'Europe/Rome'));
     $this->assertCount(2, $askScraper->getFetchedPages());
     $this->assertCount(1, $askScraper->getKeywords());
     $this->assertTrue($askScraper->scrape('baz', 2, true));
     $this->assertCount(4, $askScraper->getFetchedPages());
     $this->assertCount(0, $askScraper->getKeywords());
     $this->assertFalse($askScraper->scrapeAll());
     $this->assertTrue($askScraper->addKeywords(array('foobaz', 'foobar')));
     $this->assertTrue($askScraper->scrapeAll(2, true, 'America/Los_Angeles'));
     $this->assertCount(8, $askScraper->getFetchedPages());
     $this->assertCount(0, $askScraper->getKeywords());
     $this->assertFalse($askScraper->serialize('baz'));
     $this->assertTrue($askScraper->serialize('xml', true));
     $this->assertCount(0, $askScraper->getFetchedPages());
     $this->assertCount(8, $askScraper->getSerializedPages());
     $toCheck = array_map('Franzip\\SerpScraper\\Helpers\\FileSystemHelper::generateFileName', array_keys($askScraper->getSerializedPages()));
     $this->assertTrue($askScraper->save(true));
     $this->assertCount(0, $askScraper->getSerializedPages());
     for ($i = 0; $i < count($toCheck); $i++) {
         $xml = new \XMLReader();
         $xml->open($outDir . DIRECTORY_SEPARATOR . $toCheck[$i]);
         $xml->setParserProperty(\XMLReader::VALIDATE, true);
         $this->assertTrue($xml->isValid());
     }
     $this->assertTrue($askScraper->addKeywords(array('foobaz')));
     $this->assertTrue($askScraper->scrapeAll(3, true));
     $this->assertTrue($askScraper->serialize('json', true));
     $toCheck = array_map('Franzip\\SerpScraper\\Helpers\\FileSystemHelper::generateFileName', array_keys($askScraper->getSerializedPages()));
     $this->assertTrue($askScraper->save(true));
     for ($i = 0; $i < count($toCheck); $i++) {
         $json = file_get_contents($outDir . DIRECTORY_SEPARATOR . $toCheck[$i]);
         $this->assertNull($parser->lint($json));
     }
     $bingScraper = Builder::create($this->engines[2], array(array('foo', 'baz'), 'bing'));
     $outDir = $bingScraper->getOutDir();
     $this->assertFalse($bingScraper->scrape('bar'));
     $this->assertFalse($bingScraper->scrape('baz', 100));
     $this->assertFalse($bingScraper->scrape('baz', 1, 'baz'));
     $this->assertFalse($bingScraper->scrape('baz', 1, true, 'foobad'));
     $this->assertFalse($bingScraper->scrape('baz', 1, true, 'UTC', 'faz'));
     $this->assertFalse($bingScraper->serialize('json'));
     $this->assertTrue($bingScraper->scrape('foo', 2, true, 'Europe/Berlin'));
     $this->assertCount(2, $bingScraper->getFetchedPages());
     $this->assertCount(1, $bingScraper->getKeywords());
     $this->assertTrue($bingScraper->scrape('baz', 2, true));
     $this->assertCount(4, $bingScraper->getFetchedPages());
     $this->assertCount(0, $bingScraper->getKeywords());
//.........这里部分代码省略.........
开发者ID:franzip,项目名称:serp-scraper,代码行数:101,代码来源:SerpScraperTest.php

示例12: __construct

 /**
  * __construct
  * 
  * Builds the Chunk object
  *
  * @param string $file The filename to work with
  * @param array $options The options with which to parse the file
  * @author Dom Hastings
  * @access public
  */
 public function __construct($file, $options = array())
 {
     // merge the options together
     $this->options = array_merge($this->options, is_array($options) ? $options : array());
     $this->options['chunkSize'] *= PMXI_Plugin::getInstance()->getOption('chunk_size');
     // set the filename
     $this->file = $file;
     $is_html = false;
     $f = @fopen($file, "rb");
     while (!@feof($f)) {
         $chunk = @fread($f, 1024);
         if (strpos($chunk, "<!DOCTYPE") === 0) {
             $is_html = true;
         }
         break;
     }
     @fclose($f);
     if ($is_html) {
         return;
     }
     if (empty($this->options['element']) or $this->options['get_cloud']) {
         //$founded_tags = array();
         if (function_exists('stream_filter_register') and $this->options['filter']) {
             stream_filter_register('preprocessxml', 'preprocessXml_filter');
             $path = 'php://filter/read=preprocessxml/resource=' . $this->file;
         } else {
             $path = $this->file;
         }
         $reader = new XMLReader();
         $reader->open($path);
         $reader->setParserProperty(XMLReader::VALIDATE, false);
         while (@$reader->read()) {
             switch ($reader->nodeType) {
                 case XMLREADER::ELEMENT:
                     if (array_key_exists(str_replace(":", "_", $reader->localName), $this->cloud)) {
                         $this->cloud[str_replace(":", "_", $reader->localName)]++;
                     } else {
                         $this->cloud[str_replace(":", "_", $reader->localName)] = 1;
                     }
                     //array_push($founded_tags, str_replace(":", "_", $reader->localName));
                     break;
                 default:
                     break;
             }
         }
         unset($reader);
         /*if (!empty($founded_tags)) {            
             $element_counts = array_count_values($founded_tags);                          
             if (!empty($element_counts)){
               foreach ($element_counts as $tag => $count)
                 if (strpos($tag, ":") === false)
                     $this->cloud[$tag] = $count;                
               
               arsort($element_counts);           
             }              
           } */
         if (!empty($this->cloud) and empty($this->options['element'])) {
             arsort($this->cloud);
             $main_elements = array('node', 'product', 'job', 'deal', 'entry', 'item', 'property', 'listing', 'hotel', 'record', 'article', 'post', 'book');
             foreach ($this->cloud as $element_name => $value) {
                 if (in_array(strtolower($element_name), $main_elements)) {
                     $this->options['element'] = $element_name;
                     break;
                 }
             }
             if (empty($this->options['element'])) {
                 foreach ($this->cloud as $el => $count) {
                     $this->options['element'] = $el;
                     break;
                 }
             }
         }
     }
     if (function_exists('stream_filter_register') and $this->options['filter']) {
         stream_filter_register('preprocessxml', 'preprocessXml_filter');
         $path = 'php://filter/read=preprocessxml/resource=' . $this->file;
     } else {
         $path = $this->file;
     }
     $this->reader = new XMLReader();
     @$this->reader->open($path);
     @$this->reader->setParserProperty(XMLReader::VALIDATE, false);
 }
开发者ID:yarwalker,项目名称:ecobyt,代码行数:93,代码来源:chunk.php

示例13: fn_exim_1c_get_external_file

function fn_exim_1c_get_external_file($filename)
{
    list($dir_1c, $dir_1c_url, $dir_1c_images) = fn_rus_exim_1c_get_dir_1c();
    if (!is_dir($dir_1c)) {
        fn_mkdir($dir_1c);
    }
    $file_path = $dir_1c . $filename;
    if (Registry::get('addons.rus_exim_1c.exim_1c_schema_version') == '2.07') {
        if (file_exists($file_path) && extension_loaded('XMLReader')) {
            $xml = new XMLReader();
            $xml->open($file_path);
            $xml->setParserProperty(XMLReader::VALIDATE, true);
            if (!$xml->isValid()) {
                @unlink($file_path);
            }
        }
    }
    if (fn_exim_1c_file_is_image($filename)) {
        if (!is_dir($dir_1c_images)) {
            fn_mkdir($dir_1c_images);
        }
        $file_path = $dir_1c_images . $filename;
    }
    $file = @fopen($file_path, 'w');
    if (!$file) {
        return false;
    }
    fwrite($file, fn_get_contents('php://input'));
    fclose($file);
    return true;
}
开发者ID:askzap,项目名称:ask-zap,代码行数:31,代码来源:func.php

示例14: __construct

 /**
  * __construct
  * 
  * Builds the Chunk object
  *
  * @param string $file The filename to work with
  * @param array $options The options with which to parse the file
  * @author Dom Hastings
  * @access public
  */
 public function __construct($file, $options = array(), $debug = false)
 {
     // merge the options together
     $this->options = array_merge($this->options, is_array($options) ? $options : array());
     $this->options['chunkSize'] *= PMXI_Plugin::getInstance()->getOption('chunk_size');
     // set the filename
     $this->file = $file;
     $is_html = false;
     $f = @fopen($file, "rb");
     while (!@feof($f)) {
         $chunk = @fread($f, 1024);
         if (strpos($chunk, "<!DOCTYPE") === 0) {
             $is_html = true;
         }
         break;
     }
     @fclose($f);
     if ($is_html) {
         $path = $this->get_file_path();
         $this->is_404 = true;
         $this->reader = new XMLReader();
         @$this->reader->open($path);
         @$this->reader->setParserProperty(XMLReader::VALIDATE, false);
         return;
     }
     if (empty($this->options['element']) or $this->options['get_cloud']) {
         $path = $this->get_file_path();
         $reader = new XMLReader();
         $reader->open($path);
         $reader->setParserProperty(XMLReader::VALIDATE, false);
         while (@$reader->read()) {
             switch ($reader->nodeType) {
                 case XMLREADER::ELEMENT:
                     $localName = str_replace("_colon_", ":", $reader->localName);
                     if (array_key_exists(str_replace(":", "_", $localName), $this->cloud)) {
                         $this->cloud[str_replace(":", "_", $localName)]++;
                     } else {
                         $this->cloud[str_replace(":", "_", $localName)] = 1;
                     }
                     break;
                 default:
                     break;
             }
         }
         unset($reader);
         if (!empty($this->cloud) and empty($this->options['element'])) {
             arsort($this->cloud);
             $main_elements = array('node', 'product', 'job', 'deal', 'entry', 'item', 'property', 'listing', 'hotel', 'record', 'article', 'post', 'book', 'item_0');
             foreach ($this->cloud as $element_name => $value) {
                 if (in_array(strtolower($element_name), $main_elements)) {
                     $this->options['element'] = $element_name;
                     break;
                 }
             }
             if (empty($this->options['element'])) {
                 foreach ($this->cloud as $el => $count) {
                     $this->options['element'] = $el;
                     break;
                 }
             }
         }
     }
     $path = $this->get_file_path();
     $this->reader = new XMLReader();
     @$this->reader->open($path);
     @$this->reader->setParserProperty(XMLReader::VALIDATE, false);
 }
开发者ID:mynein,项目名称:myne,代码行数:77,代码来源:chunk.php

示例15: XMLReader

<?php

$indent = 5;
/* Number of spaces to indent per level */
$xml = new XMLReader();
$xml->open("dtdexample.xml");
$xml->setParserProperty(XMLREADER::LOADDTD, TRUE);
$xml->setParserProperty(XMLREADER::VALIDATE, TRUE);
while ($xml->read()) {
    /* Print node name indenting it based on depth and $indent var */
    print str_repeat(" ", $xml->depth * $indent) . $xml->name . "\n";
    if ($xml->hasAttributes) {
        $attCount = $xml->attributeCount;
        print str_repeat(" ", $xml->depth * $indent) . " Number of Attributes: " . $xml->attributeCount . "\n";
    }
}
print "\n\nValid:\n";
var_dump($xml->isValid());
开发者ID:cefalo19,项目名称:php-src,代码行数:18,代码来源:xmlreader_validatedtd.php


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