PHPはaddChild()関数
例
ボディとフッタ要素は、その要素の子要素を追加します。
<?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リファレンスマニュアル