PHP addChild()関数
例
body 要素と footer 要素に子要素を追加します:
<?php
$note=<<<XML
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
XML;
$xml=new SimpleXMLElement($note);
// Add a child element to the body element
$xml->body->addChild("date","2013-01-01");
// Add a child element after the last element inside note
$footer=$xml->addChild("footer","Some footer text");
echo $xml->asXML();
?>
$note=<<<XML
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
XML;
$xml=new SimpleXMLElement($note);
// Add a child element to the body element
$xml->body->addChild("date","2013-01-01");
// Add a child element after the last element inside note
$footer=$xml->addChild("footer","Some footer text");
echo $xml->asXML();
?>
例を実行 »
定義と使用法
addChild() 関数は SimpleXML 要素に子要素を追加します。
構文
addChild(name,value,ns);
| パラメータ | 説明 |
|---|---|
| name | 必須。追加する子要素の名前を指定します。 |
| value | 任意。子要素の値を指定します。 |
| ns | 任意。子要素の名前空間を指定します。 |
技術詳細
| 戻り値: | XML に追加された子要素を表す SimpleXMLElement オブジェクトを返します。 |
|---|---|
| PHP バージョン: | 5.1.3+ |
PHP SimpleXML リファレンスマニュアル その他の拡張