PHP 8.4.0 RC4 available for testing

XMLReader

Добавить

Примечания пользователей 1 note

up
1
Anonymous
6 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