如果命名空间嵌套在 xml 中,则您必须循环遍历节点。
<?php
$xml = <<<XML
<?xml version="1.0" encoding="UTF-8"?>
<people xmlns:p="http://example.org/ns" xmlns:t="http://example.org/test">
<items>
<title>This is a test of namespaces and my patience</title>
<p:person id="1">John Doe</p:person>
<p:person id="2">Susie Q. Public</p:person>
<p:person id="1">Fish Man</p:person>
</items>
</people>
XML;
$sxe = new SimpleXMLElement($xml);
foreach ($sxe as $out_ns)
{
$ns = $out_ns->getNamespaces(true);
$child = $out_ns->children($ns['p']);
foreach ($child as $out)
{
echo $out . "<br />";
}
}
?>