public string CreateNamespace(string prefix, string namespaceUri, XPathNavigator source)
{
if (string.IsNullOrEmpty(namespaceUri) == false)
{
source = source.Clone();
source.MoveToRoot();
source.MoveToChild(XPathNodeType.Element);
if (string.IsNullOrEmpty(prefix))
prefix = AddNamespace(namespaceUri);
var existing = source.GetNamespace(prefix);
if (existing == namespaceUri) return prefix;
if (string.IsNullOrEmpty(existing) == false)
return null;
source.CreateAttribute("xmlns", prefix, "", namespaceUri);
}
return prefix;
}