demo_func_simplexml_addchild.php:
<!DOCTYPE html> <html> <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 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(); ?> <p>Select View Source to see the added "date" and "footer" elements.</p> </body> </html>