代码
<?php
$xml = <<<XML
<xml>
<body bgcolor="red">red</body>
<body bgcolor="green">green</body>
</xml>
XML;
$dom = new DomDocument();
$dom->loadXML($xml);
$xpath = new DomXpath($dom);
$nodes = $xpath->query("*[local-name()='body']", $dom->documentElement);
echo $nodes->item(0)->getAttributeNode('bgcolor')->value;
?>
The result:
red