Add a child element to the body element and footer element:
<?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();?>The addChild() function adds a child element to a SimpleXML element.
addChild( name,value,ns );
parameter | describe |
---|---|
name | Required. Specifies the name of the child element to be added. |
value | Optional. Specifies the value of the child element. |
ns | Optional. Specifies the namespace of child elements. |
Return value: | Returns a SimpleXMLElement object representing a child element added to XML. |
---|---|
PHP version: | 5.1.3+ |