Php/func simplexml attributes
来自菜鸟教程
PHP attributes()函数
例
返回XML <body>元素的属性和值:
<?php
$note=<<<XML
<note>
<to>Tove</to>
<from>Jani</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>";
}
?>
定义和用法
attribute()函数返回XML元素的属性和值。
句法
SimpleXMLElement::attributes(ns, prefix)
参数值
| 参数 | 描述 |
|---|---|
| ns | 可选的。指定检索到的属性的名称空间 |
| prefix | 可选的。如果为,则指定TRUE
ns 是前缀,如果为FALSE ns 是URI。默认为FALSE |
技术细节
| 返回值: | 成功的SimpleXMLElement对象 |
| PHP版本: | 5.0+ |