attributes
Returns the attribute/value of the element.
attributes() function returns the attributes and values of an XML element.
返回 XML <body> 元素的属性和值:
<?php
$note=<<<XML
<note>
<to>George</to>
<from>John</from>
<heading>Reminder</heading>
<body date="2014-01-01" type="private">Do not forget me this weekend!</body>
</note>
XML;
$xml = simplexml_load_string($note);
foreach($xml->body[0]->attributes() as $a => $b)
{
echo $a,'="',$b,"<br>";
}
?>
运行实例
SimpleXMLElement :: attributes ( ns , prefix )
| parameter | describe |
|---|---|
| ns | Optional. Specifies the namespace for the retrieved attribute. |
| prefix | Optional. TRUE is specified if ns is a prefix; if ns is a URI, FALSE is specified. The default is FALSE. |