XMLReader

Introduction

The XMLReader extension is an XML Pull parser. The reader acts as a cursor going forward on the document stream and stopping at each node on the way.

Encoding

It is important to note that internally, libxml uses the UTF-8 encoding and as such, the encoding of the retrieved contents will always be in UTF-8 encoding.

Found A Problem?

Learn How To Improve This PageSubmit a Pull RequestReport a Bug
+add a note

User Contributed Notes 1 note

up
5
Anonymous
2 years ago
Allright, I'll do it myself:
$xmlreader = XMLReader::open('xml_file.xml');
$indent = 0;
while ($xmlreader->read() !== FALSE)
{
 switch ($xmlreader->nodeType)
 {
 case XMLReader::ELEMENT:
 echo str_repeat("\t", ($xmlreader->isEmptyElement ? $indent : $indent++)), '[element]: ', $xmlreader->name, "\n";
 break;
 case XMLReader::TEXT:
 echo str_repeat("\t", $indent), $xmlreader->value, "\n";
 break;
 case XMLReader::END_ELEMENT:
 echo str_repeat("\t", --$indent), '[end element]: ', $xmlreader->name, "\n";
 break;
 }
}
+add a note

AltStyle によって変換されたページ (->オリジナル) /