[PHP] To display some attribute of the node in the XML document.

 

 

 

代码
<?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

posted @ 2010-05-12 16:57  DavidHHuan  阅读(193)  评论(0编辑  收藏  举报