If you have trouble parsing xml documents with text tags bigger than 10MB, this might help you:
<?php
$xmlreader = new XMLReader();
$xmlreader->open($uri, null, 1<<19);
?>
Since in libxml there is a constant
XML_PARSE_HUGE = 1<<19
which enables parsing xml documents with huge texts.
Please note that this option is not accessible using the setParserProperty method and that there is currently no constant to do the work, which will hopefully change soon:
http://bugs.php.net/bug.php?id=49660
XMLReader::read
(PHP 5 >= 5.1.2)
XMLReader::read — ドキュメント内の次のノードに移動する
説明
bool XMLReader::read
( void
)
ドキュメント内の次のノードにカーソルを移動します。
返り値
成功した場合に TRUE を、失敗した場合に FALSE を返します。
参考
- XMLReader::moveToElement - 現在の属性の親要素にカーソルを移動する
- XMLReader::moveToAttribute - 指定した名前の属性にカーソルを移動する
- XMLReader::next - すべてのサブツリーを飛ばして、次のノードにカーソルを移動する
XMLReader::read
Yannik
10-Nov-2009 08:38
10-Nov-2009 08:38
jirka at kosek dot cz
08-Feb-2006 06:01
08-Feb-2006 06:01
libxml2 contains much more useful method readString() that will read and return whole text content of element. You can call it after receiving start tag (XMLReader::ELEMENT). You can use this PHP code to emulate this method until PHP will directly call underlying libxml2 implementation.
<?php
class XMLReader2 extends XMLReader
{
function readString()
{
$depth = 1;
$text = "";
while ($this->read() && $depth != 0)
{
if (in_array($this->nodeType, array(XMLReader::TEXT, XMLReader::CDATA, XMLReader::WHITESPACE, XMLReader::SIGNIFICANT_WHITESPACE)))
$text .= $this->value;
if ($this->nodeType == XMLReader::ELEMENT) $depth++;
if ($this->nodeType == XMLReader::END_ELEMENT) $depth--;
}
return $text;
}
}
?>
Just use XMLReader2 instead of XMLReader.
