Merge two xml only with SimpleXML :
Function corrected if note containe only value.
<?php
function mergeXML(&$base, $add)
{
if ( $add->count() != 0 )
$new = $base->addChild($add->getName());
else
$new = $base->addChild($add->getName(), $add);
foreach ($add->attributes() as $a => $b)
{
$new->addAttribute($a, $b);
}
if ( $add->count() != 0 )
{
foreach ($add->children() as $child)
{
mergeXML($new, $child);
}
}
}
?>
Use : <?php mergeXML($xmlElement, simplexml_load_string($toMerge)) ?>