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


PHP XMLReader::XML方法代码示例

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


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

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

示例2: filter

 public function filter($value)
 {
     $this->_initReaderWriter();
     $this->_reader->XML($value);
     $this->_doXmlTrim();
     $this->_writer->endDocument();
     return $this->_writer->outputMemory();
 }
开发者ID:shevron,项目名称:stoa,代码行数:8,代码来源:XmlTrim.php

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

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

示例5: parseErrorResponse

 public function parseErrorResponse($statusCode, $content, MnsException $exception = NULL)
 {
     $this->succeed = FALSE;
     $xmlReader = new \XMLReader();
     try {
         $xmlReader->XML($content);
         $result = XMLParser::parseNormalError($xmlReader);
         if ($result['Code'] == Constants::QUEUE_NOT_EXIST) {
             throw new QueueNotExistException($statusCode, $result['Message'], $exception, $result['Code'], $result['RequestId'], $result['HostId']);
         }
         if ($result['Code'] == Constants::MESSAGE_NOT_EXIST) {
             throw new MessageNotExistException($statusCode, $result['Message'], $exception, $result['Code'], $result['RequestId'], $result['HostId']);
         }
         throw new MnsException($statusCode, $result['Message'], $exception, $result['Code'], $result['RequestId'], $result['HostId']);
     } catch (\Exception $e) {
         if ($exception != NULL) {
             throw $exception;
         } elseif ($e instanceof MnsException) {
             throw $e;
         } else {
             throw new MnsException($statusCode, $e->getMessage());
         }
     } catch (\Throwable $t) {
         throw new MnsException($statusCode, $t->getMessage());
     }
 }
开发者ID:lizhengqiang,项目名称:thinkphp,代码行数:26,代码来源:ReceiveMessageResponse.php

示例6: testMoveToClosingElementWithSelfClosingTag

 /**
  * Tests JFeedParser::moveToClosingElement() with self-closing tags.
  *
  * @return  void
  *
  * @since   12.3
  */
 public function testMoveToClosingElementWithSelfClosingTag()
 {
     // Set the XML for the internal reader and move the stream to the first <node> element.
     $this->_reader->XML('<root><node test="first" /><node test="second"></node></root>');
     // Advance the reader to the first <node> element.
     do {
         $this->_reader->read();
     } while ($this->_reader->name != 'node');
     // Ensure that the current node is <node test="first">.
     $this->assertEquals(XMLReader::ELEMENT, $this->_reader->nodeType);
     $this->assertEquals('node', $this->_reader->name);
     $this->assertEquals('first', $this->_reader->getAttribute('test'));
     // Move to the closing element, which should be </node>.
     TestReflection::invoke($this->_instance, 'moveToClosingElement');
     $this->assertEquals(true, $this->_reader->isEmptyElement);
     $this->assertEquals('node', $this->_reader->name);
     // Advance the reader to the next element.
     do {
         $this->_reader->read();
     } while ($this->_reader->nodeType != XMLReader::ELEMENT);
     // Ensure that the current node is <node test="first">.
     $this->assertEquals(XMLReader::ELEMENT, $this->_reader->nodeType);
     $this->assertEquals('node', $this->_reader->name);
     $this->assertEquals('second', $this->_reader->getAttribute('test'));
 }
开发者ID:nirpan,项目名称:joomla-cms,代码行数:32,代码来源:JFeedParserTest.php

示例7: xmlTree

 public static function &buildTree($source, $mode = XMLDocument::BUILD_MODE_FROM_FILE, $ns = NULL)
 {
     if ($mode == XMLDocument::BUILD_MODE_FROM_FILE) {
         if (($content = Filesystem::getFileContent($source)) === NULL) {
             return NULL;
         }
     } else {
         if ($source == "" || $source == NULL) {
             return new xmlTree();
         }
         $content = $ns == NULL ? "<ROOT>" . $source . "</ROOT>" : "<ROOT xmlns:{$ns}=\".\">" . $source . "</ROOT>";
     }
     /*$content = ereg_replace( "&amp;", "&", $content );
     		$content = ereg_replace( "&", "&amp;", $content );*/
     //echo $content;
     $content = preg_replace("/&amp;/", "&", $content);
     $content = preg_replace("/&/", "&amp;", $content);
     $content = iconv("windows-1251", "UTF-8", $content);
     $reader = new XMLReader();
     if ($reader->XML($content)) {
         $_docTree = NULL;
         $_docTree = new xmlTree();
         self::_appendChilds($_docTree->getCurrent(), $reader, 0);
         $reader = NULL;
         return $_docTree;
     } else {
         self::raiseException(ERR_XML_INVALID_XML, $content);
         return NULL;
     }
 }
开发者ID:nirwander,项目名称:holkinsengine,代码行数:30,代码来源:xmldocument.class.php

示例8: testXml

 private static function testXml()
 {
     $xml = new \XMLReader();
     $xml->XML(self::$TestXml);
     $xmlarray = xmlWithArray::xmlToarray($xml);
     return $xmlarray;
 }
开发者ID:majixian,项目名称:XML-Array,代码行数:7,代码来源:xmlWithArrayTest.php

示例9: parseErrorResponse

 public function parseErrorResponse($statusCode, $content, MnsException $exception = NULL)
 {
     $this->succeed = FALSE;
     $xmlReader = new \XMLReader();
     try {
         $xmlReader->XML($content);
         $result = XMLParser::parseNormalError($xmlReader);
         if ($result['Code'] == Constants::TOPIC_NOT_EXIST) {
             throw new TopicNotExistException($statusCode, $result['Message'], $exception, $result['Code'], $result['RequestId'], $result['HostId']);
         }
         if ($result['Code'] == Constants::INVALID_ARGUMENT) {
             throw new InvalidArgumentException($statusCode, $result['Message'], $exception, $result['Code'], $result['RequestId'], $result['HostId']);
         }
         if ($result['Code'] == Constants::MALFORMED_XML) {
             throw new MalformedXMLException($statusCode, $result['Message'], $exception, $result['Code'], $result['RequestId'], $result['HostId']);
         }
         throw new MnsException($statusCode, $result['Message'], $exception, $result['Code'], $result['RequestId'], $result['HostId']);
     } catch (\Exception $e) {
         if ($exception != NULL) {
             throw $exception;
         } elseif ($e instanceof MnsException) {
             throw $e;
         } else {
             throw new MnsException($statusCode, $e->getMessage());
         }
     } catch (\Throwable $t) {
         throw new MnsException($statusCode, $t->getMessage());
     }
 }
开发者ID:lizhengqiang,项目名称:thinkphp,代码行数:29,代码来源:PublishMessageResponse.php

示例10: parseErrorResponse

 public function parseErrorResponse($statusCode, $content, MnsException $exception = NULL)
 {
     $this->succeed = FALSE;
     $xmlReader = new \XMLReader();
     try {
         $xmlReader->XML($content);
         while ($xmlReader->read()) {
             if ($xmlReader->nodeType == \XMLReader::ELEMENT) {
                 switch ($xmlReader->name) {
                     case Constants::ERROR:
                         $this->parseNormalErrorResponse($xmlReader);
                         break;
                     default:
                         // case Constants::Messages
                         $this->parseBatchSendErrorResponse($xmlReader);
                         break;
                 }
             }
         }
     } catch (\Exception $e) {
         if ($exception != NULL) {
             throw $exception;
         } elseif ($e instanceof MnsException) {
             throw $e;
         } else {
             throw new MnsException($statusCode, $e->getMessage());
         }
     } catch (\Throwable $t) {
         throw new MnsException($statusCode, $t->getMessage());
     }
 }
开发者ID:lizhengqiang,项目名称:thinkphp,代码行数:31,代码来源:BatchSendMessageResponse.php

示例11: parse

 /**
  * Parse a beer XML, returning an array of the record objects found
  *
  * @param string $xml
  * @return IRecipe[]|IEquipment[]|IFermentable[]|IHop[]|IMashProfile[]|IMisc[]|IStyle[]|IWater[]|IYeast[]
  */
 public function parse($xml)
 {
     $this->xmlReader->XML($xml);
     $records = array();
     while ($this->xmlReader->read()) {
         // Find records
         if ($this->xmlReader->nodeType == \XMLReader::ELEMENT && isset($this->tagParsers[$this->xmlReader->name])) {
             $recordParser = new $this->tagParsers[$this->xmlReader->name]();
             /** @var $recordParser Record */
             $recordParser->setXmlReader($this->xmlReader);
             $recordParser->setRecordFactory($this->recordFactory);
             $records[] = $recordParser->parse();
         }
     }
     $this->xmlReader->close();
     return $records;
 }
开发者ID:georgeh,项目名称:php-beerxml,代码行数:23,代码来源:Parser.php

示例12: validate

 /**
  * Проверка по схеме
  */
 public function validate($schemaPath)
 {
     $xr = new XMLReader();
     $xr->XML($this->toXmlStr());
     $xr->setSchema($schemaPath);
     while ($xr->read()) {
     }
 }
开发者ID:servandserv,项目名称:happymeal,代码行数:11,代码来源:XMLBase.php

示例13: loadXmlContent

 protected function loadXmlContent($content)
 {
     $xmlReader = new \XMLReader();
     $isXml = $xmlReader->XML($content);
     if ($isXml === FALSE) {
         throw new MnsException($statusCode, $content);
     }
     return $xmlReader;
 }
开发者ID:yunwuxin,项目名称:aliyun_mns,代码行数:9,代码来源:BaseResponse.php

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

示例15: XML

 public function XML($source, $encoding = NULL, $options = 0)
 {
     if (!@parent::XML($source, $encoding, $options | LIBXML_NONET | LIBXML_NOENT)) {
         if (false !== ($error = libxml_get_last_error())) {
             libxml_clear_errors();
             $ex = new XmlParseException('Unable to open XML stream from given XML source');
             $ex->addError(new XmlError($error->level, $error->message));
             throw $ex;
         }
         throw new XmlParseException('Unable to open XML stream from given XML source');
     }
     return true;
 }
开发者ID:koolkode,项目名称:xml,代码行数:13,代码来源:XmlStreamReader.php


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