XMLReader

add a note

User Contributed Notes 1 note

up
1
Anonymous
2 months 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;
}
}
To Top