public static string NsPrefix(this XmlNamespaceManager manager, string currentNamespace, string currentPath) { var prefix = string.Empty; // Apply the namespace to the node if a namespace is defined and we don't have one yet if (!string.IsNullOrEmpty(currentNamespace)) { prefix = manager.LookupPrefix(currentNamespace); if (string.IsNullOrEmpty(prefix)) { throw new ObjectNotFoundException( string.Concat( "No prefix for namespace: " + currentNamespace, Environment.NewLine, "Current path: " + currentPath, Environment.NewLine, "Registered namespaces: " + manager.GetRegisteredNamespaces())); } } return(prefix); }