本文整理汇总了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();
}
示例2: filter
public function filter($value)
{
$this->_initReaderWriter();
$this->_reader->XML($value);
$this->_doXmlTrim();
$this->_writer->endDocument();
return $this->_writer->outputMemory();
}
示例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();
}
示例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);
}
示例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());
}
}
示例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'));
}
示例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( "&", "&", $content );
$content = ereg_replace( "&", "&", $content );*/
//echo $content;
$content = preg_replace("/&/", "&", $content);
$content = preg_replace("/&/", "&", $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;
}
}
示例8: testXml
private static function testXml()
{
$xml = new \XMLReader();
$xml->XML(self::$TestXml);
$xmlarray = xmlWithArray::xmlToarray($xml);
return $xmlarray;
}
示例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());
}
}
示例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());
}
}
示例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;
}
示例12: validate
/**
* Проверка по схеме
*/
public function validate($schemaPath)
{
$xr = new XMLReader();
$xr->XML($this->toXmlStr());
$xr->setSchema($schemaPath);
while ($xr->read()) {
}
}
示例13: loadXmlContent
protected function loadXmlContent($content)
{
$xmlReader = new \XMLReader();
$isXml = $xmlReader->XML($content);
if ($isXml === FALSE) {
throw new MnsException($statusCode, $content);
}
return $xmlReader;
}
示例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" />';
}
示例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;
}