SimpleXMLElement->attributes

(no version information, might be only in CVS)

SimpleXMLElement->attributes --  Identifies an element's attributes

Description

SimpleXMLElement simplexml_element->attributes ( [string data] )

This function provides the attributes and values defined within an xml tag.

注: SimpleXML 建立了一條給大部分方法增加交談式屬性的規則。這些屬性不能夠使用 var_dump() 或其它檢查對象的方法來檢視。

例子 1. Interpret an XML string

<?php
$string 
= <<<XML
<a>
 <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";
}
?>

This script will display:

name="one"
game="lonely"