<?php
$dom = new DomDocument();
$dom->loadXml('<root attr1="a" attr2="b"><foo></foo></root>');
$dom2 = new DomDocument();
$dom2->appendChild(
$dom2->importNode($dom->documentElement->cloneNode(false), true)
);
header('Content-Type: text/xml; charset="UTF-8"');
echo $dom2->saveXml();