PHP attributes()関数
例
XML の body 要素の属性と値を返します:
<?php
$note=<<<XML
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body date="2013-01-01" type="private">Don't forget me this weekend!</body>
</note>
XML;
$xml=simplexml_load_string($note);
foreach($xml->body[0]->attributes() as $a => $b)
{
echo $a,'="',$b,""<br>";
}
?>
$note=<<<XML
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body date="2013-01-01" type="private">Don't forget me this weekend!</body>
</note>
XML;
$xml=simplexml_load_string($note);
foreach($xml->body[0]->attributes() as $a => $b)
{
echo $a,'="',$b,""<br>";
}
?>
例を実行 »
定義と使用法
attributes() 関数は XML タグの属性と値を返します。
構文
attributes(ns,is_prefix);
| パラメータ | 説明 |
|---|---|
| ns | オプション。取得する属性の名前空間を指定します。 |
| is_prefix | オプション。ブール値を指定します。もしnsプレフィックスの場合は TRUE、もしnsURI の場合は FALSE。デフォルトは FALSE です。 |
技術詳細
| 戻り値: | 成功した場合は SimpleXMLElement オブジェクトを返します。 |
|---|---|
| PHP バージョン: | 5.0.1+ |
PHP SimpleXML リファレンスマニュアル その他の拡張モジュール