private void CopyNamespaces(XPathNavigator navigator, XPathNamespaceScope nsScope) {
Debug.Assert(navigator.NodeType == XPathNodeType.Element, "Only elements have namespaces to copy");
// Default namespace undeclaration isn't included in navigator's namespace list, so add it now
if (navigator.NamespaceURI.Length == 0) {
Debug.Assert(navigator.LocalName.Length != 0, "xmlns:foo='' isn't allowed");
WriteNamespaceDeclarationUnchecked(string.Empty, string.Empty);
}
// Since the namespace list is arranged in reverse-document order, recursively reverse it.
if (navigator.MoveToFirstNamespace(nsScope)) {
CopyNamespacesHelper(navigator, nsScope);
navigator.MoveToParent();
}
}