(PHP 5 >= 5.0.1)
SimpleXMLElement::attributes — Identifies an element's attributes
This function provides the attributes and values defined within an xml tag.
Note: SimpleXML 创建了一条给大部分方法增加交互式属性的规则。这些属性不能够使用 var_dump() 或其它检查对象的方法来查看。
An optional namespace for the retrieved attributes
Default to FALSE
Example #1 Interpret an XML string
<?php
$string = <<<XML
<a xmlns:b>
<foo name="one" game="lonely">1</foo>
</a>
XML;
$xml = simplexml_load_string($string);
foreach($xml->foo[0]->attributes() as $a => $b) {
echo $a,'="',$b,"\"\n";
}
?>
上例将输出:
name="one" game="lonely"