downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

XMLReader::readInnerXML> <XMLReader::open
Last updated: Fri, 20 May 2011

view this page in

XMLReader::read

(PHP 5 >= 5.1.2)

XMLReader::readSe mueve al siguiente nodo en el documento

Descripción

bool XMLReader::read ( void )

Mueve el cursor al siguiente nodo en el documento.

Valores devueltos

Devuelve TRUE en caso de éxito o FALSE en caso de error.

Ver también



XMLReader::readInnerXML> <XMLReader::open
Last updated: Fri, 20 May 2011
 
add a note add a note User Contributed Notes XMLReader::read
andy at siliconrockstar dot com 16-May-2011 08:01
A very simple way to avoid typing $reader->read() multiple times when you want to skip some nodes:

<?php
class smartXMLReader extends XMLReader {
    public function
readTimes($count) {
       
$i = 0;
        while(
$i < $count){
           
$this->read();
           
$i++;
        }
    }
}
?>

Using this smartXMLReader,

<?php
$reader
->readTimes(3);
?>

is equivalent to

<?php
$reader
->read();
$reader->read();
$reader->read();
?>

Makes getting around in your XML document a bit easier :)
caddozzone at gmail dot com 01-Feb-2011 09:58
This class XMLReader2 is dangerous: charge all XML in memory, it can cause an out of memory error. It's the same that SimpleXML does.
Please take care.
Yannik 10-Nov-2009 11:38
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
jirka at kosek dot cz 08-Feb-2006 09: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.

 
show source | credits | stats | sitemap | contact | advertising | mirror sites