When you use function/method below, php automaticaly inserts namespaces (if you have some). If you want to join xml files exactly, then you can just use placeholders and treat xml as a string.
<?php
function joinXMLStrings($file1, $file2)
{
$file2 = trim(preg_replace('/<\?xml.*\?>/', '', $file2, 1));
$file1 = trim(preg_replace('/<\?file2\s\?>/', $file2, $file1, 1));
}
?>
so function looks like this and you insert two xml files. First file has to have placeholder (where you insert file2). Placeholder in this case will be <?file2 ?>
!!!this is only for ilustration - test before you use it