好的,我自己来做吧
$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;
}
}