/// <summary>
        /// Creates a new XPathNavigator using the same source but positioned at a new root.
        /// </summary>
        /// <returns>A new XPathNavigator using the same source and positioned at a new root.</returns>
        /// <remarks>The new root can be above this navigator's root.</remarks>
        public XPathNavigator CloneWithNewRoot(int id, int maxDepth = int.MaxValue)
        {
            DebugEnter("CloneWithNewRoot");

            State state = null;

            if (id <= 0)
            {
                state = new State(_source.Root, null, null, 0, StatePosition.Root);
            }
            else
            {
                var content = SourceGet(id);
                if (content != null)
                {
                    state = new State(content, null, null, 0, StatePosition.Root);
                }
            }

            NavigableNavigator clone = null;

            if (state != null)
            {
                clone = new NavigableNavigator(this, state, maxDepth);
                DebugCreate(clone);
                DebugReturn("[XPathNavigator]");
            }
            else
            {
                DebugReturn("[null]");
            }

            return(clone);
        }
        /// <summary>
        /// Creates a new XPathNavigator positioned at the same node as this XPathNavigator.
        /// </summary>
        /// <returns>A new XPathNavigator positioned at the same node as this XPathNavigator.</returns>
        public override XPathNavigator Clone()
        {
            DebugEnter("Clone");
            var nav = new NavigableNavigator(this);

            DebugCreate(nav);
            DebugReturn("[XPathNavigator]");
            return(nav);
        }
        ///// <summary>
        ///// Initializes a new instance of the <see cref="NavigableNavigator"/> class with a content source, a name table and a state.
        ///// </summary>
        ///// <param name="source">The content source.</param>
        ///// <param name="nameTable">The name table.</param>
        ///// <param name="state">The state.</param>
        ///// <param name="maxDepth">The maximum depth.</param>
        ///// <remarks>Privately used for cloning a navigator.</remarks>
        //private NavigableNavigator(INavigableSource source, XmlNameTable nameTable, State state, int maxDepth)
        //    : this(source, rootId: 0, maxDepth: maxDepth)
        //{
        //    _nameTable = nameTable;
        //    _state = state;
        //}

        /// <summary>
        /// Initializes a new instance of the <see cref="NavigableNavigator"/> class as a clone.
        /// </summary>
        /// <param name="orig">The cloned navigator.</param>
        /// <param name="state">The clone state.</param>
        /// <param name="maxDepth">The clone maximum depth.</param>
        /// <remarks>Privately used for cloning a navigator.</remarks>
        private NavigableNavigator(NavigableNavigator orig, State state = null, int maxDepth = -1)
            : this(orig._source, rootId : 0, maxDepth : orig._maxDepth)
        {
            _nameTable = orig._nameTable;

            _state = state ?? orig._state.Clone();
            if (state != null && maxDepth < 0)
            {
                throw new ArgumentException("Both state and maxDepth are required.");
            }
            _maxDepth = maxDepth < 0 ? orig._maxDepth : maxDepth;

            _contents = orig._contents;
        }
        void DebugCreate(NavigableNavigator nav)
        {
#if DEBUGNAVIGATOR
            Debug("Create: [NavigableNavigator::{0}]", nav._uid);
#endif
        }