If you need to clone node including all child DOMNode elements:
private function cloneNode($node){
$nd = new DOMNode();
for ($i = 0; $i < $node->childNodes->length; $i++) {
$child = $node->childNodes->item($i);
if ($child->nodeType === XML_TEXT_NODE) {
$nd->appendChild($node->cloneNode(true));
}
else{
$nd->appendChild($this->cloneNode($child));
}
}
return $nd;
}