PHP addAttribute()関数
例
ルート要素(<note>)と<body>要素に属性を追加します。
<?php
$note=<<<XML
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Do not forget me this weekend!</body>
</note>
XML;
$xml = new SimpleXMLElement($note);
// Add attribute to root element
$xml->addAttribute("type","private");
// Add attribute to body element
$xml->body->addAttribute("date","2014-01-01");
echo $xml->asXML();
?>
定義と使用法
addAttribute()関数は、SimpleXML要素に属性を追加します。
構文
SimpleXMLElement::addAttribute(name, value, ns)
パラメータ値
Parameter | Description |
---|---|
name | Required. Specifies the name of the attribute to add |
value | Optional. Specifies the value of the attribute |
ns | Optional. Specifies a namespace for the attribute |
技術的な詳細
戻り値: | 何もない |
---|---|
PHPバージョン: | 5.1.3+ |
❮PHPSimpleXMLリファレンス