Php/func simplexml addchild
来自菜鸟教程
PHP addChild()函数
例
将子元素添加到<body>元素,并添加一个新的<footer>元素:
<?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 a child element to the body element
$xml->body->addChild("date","2014-01-01");
// Add a child element after the last element inside note
$footer = $xml->addChild("footer","Some footer text");
echo $xml->asXML();
?>
定义和用法
addChild()函数将子元素追加到SimpleXML元素。
句法
SimpleXMLElement::addChild(name, value, ns)
参数值
| 参数 | 描述 |
|---|---|
| name | 需要。指定要添加的子元素的名称 |
| value | 可选的。指定子元素的值 |
| ns | 可选的。指定子元素的名称空间 |
技术细节
| 返回值: | 一个SimpleXMLElement对象,表示添加到XML节点的子级 |
| PHP版本: | 5.1.3+ |