- simplexml_load_string: documentation ( source)
- dom_import_simplexml: documentation ( source)
- simplexml_import_dom: documentation ( source)
<?php
$thing = simplexml_load_string(
'<thing>
<node n="1"><child/></node>
</thing>'
);
$dom_thing = dom_import_simplexml($thing);
$dom_node = dom_import_simplexml($thing->node);
$dom_new = $dom_thing->appendChild($dom_node->cloneNode(true));
$new_node = simplexml_import_dom($dom_new);
$new_node['n'] = 2;
echo $thing->asXML();