SimpleXMLElement->attributes()

(no version information, might be only in CVS)

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

说明

class SimpleXMLElement {

SimpleXMLElement attributes ( [string ns [, bool is_prefix]] )

}

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

注意: SimpleXML 创建了一条给大部分方法增加交互式属性的规则。这些属性不能够使用 var_dump() 或其它检查对象的方法来查看。

参数

ns

An optional namespace for the retrieved attributes

is_prefix

Default to FALSE

返回值

范例

例 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"