public static CustomXmlPart ReplaceNamespace(this CustomXmlPart part, XNamespace newNs, string newPrefix) { if (part == null) { throw new ArgumentNullException("part"); } if (newNs == null) { throw new ArgumentNullException("newNs"); } var oldRoot = part.GetRootElement(); if (oldRoot == null) { return(null); } var oldNs = oldRoot.Name.Namespace; var newRoot = ReplaceNamespace(oldRoot, oldNs, newNs, newPrefix); part.SetRootElement(newRoot); return(part); }