Regrading this code:
var tmpNewNode = xdoc.ImportNode(newNode, true); if (oldNode.ParentNode != null) { oldNode.ParentNode.ReplaceChild(tmpNe
add default namespace to your xdoc