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.
XMLReader::read
(PHP 5 >= 5.1.2)
XMLReader::read — Move to next node in document
Descrierea
bool XMLReader::read
( void
)
Moves cursor to the next node in the document.
Valorile întroarse
Întoarce valoarea TRUE în cazul succesului sau FALSE în cazul eşecului.
Vedeţi de asemenea
- XMLReader::moveToElement - Position cursor on the parent Element of current Attribute
- XMLReader::moveToAttribute - Move cursor to a named attribute
- XMLReader::next - Move cursor to next node skipping all subtrees
XMLReader::read
jirka at kosek dot cz
08-Feb-2006 09:01
08-Feb-2006 09:01
