|
Related Examples ( Source code ) » xmlreader read Examples ( Source code ) » Use for loop to read all query result Examples ( Source code ) » Listing the Contents of a Directory with readdir() Examples ( Source code ) » readdir Examples ( Source code ) » Read the content from a directory Examples ( Source code ) » Reading Contents from a Directory Examples ( Source code ) » Close a file after reading Examples ( Source code ) » Is the file readable Examples ( Source code ) » Reading a Specific Character Examples ( Source code ) » Reading Specific Data from a File Examples ( Source code ) » Reading from a File Examples ( Source code ) » Opening and Reading a File Line by Line Examples ( Source code ) » Reading a File with fread() Examples ( Source code ) » File read by char Examples ( Source code ) » Read text file into array and output Examples ( Source code ) » Read text file with format Code Examples / Notes » xmlreader readjirka
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. |
Change LanguageXMLReader::close XMLReader::expand XMLReader::getAttribute XMLReader::getAttributeNo XMLReader::getAttributeNs XMLReader::getParserProperty XMLReader::isValid XMLReader::lookupNamespace XMLReader::moveToAttribute XMLReader::moveToAttributeNo XMLReader::moveToAttributeNs XMLReader::moveToElement XMLReader::moveToFirstAttribute XMLReader::moveToNextAttribute XMLReader::next XMLReader::open XMLReader::read XMLReader::setParserProperty XMLReader::setRelaxNGSchema XMLReader::setRelaxNGSchemaSource XMLReader::XML |