This is my starting xml :
&
Some good examples on how to append XML nodes can be found in the PHP manual. Like this one on how to use the SimpleXMLElement class to add a child node.
With DOMDocument it's as easy as this:
$child = new DOMElement('children');
$parent->appendChild($child);
Whereas $parent
is the DOMElement
parent which (after you have updated your question) to aquire is part of your problem:
// append <children> to the first <child> element
$parent = $dom->getElementsByTagName('child')->item(0);
$child = new DOMElement('children');
$parent->appendChild($child);
Since you have tagged php i am assuming you are looking for a solution in PHP did you try the following:
$myxml = new SimpleXMLElement($xmlstr);
$myxml->child[0]->addChild('children');
See: http://www.php.net/manual/en/simplexml.examples-basic.php for a good set of examples on XML manipulation in PHP