MoveToFollowing() public abstract method

Reposition the navigator to the next following node (inc. descendants); skip over filtered nodes. If there are no matching nodes, then return false.
public abstract MoveToFollowing ( XPathNavigator navigator, XPathNavigator navigatorEnd ) : bool
navigator System.Xml.XPath.XPathNavigator
navigatorEnd System.Xml.XPath.XPathNavigator
return bool
Example #1
0
        public bool MoveNext()
        {
            if (!_navStack.IsEmpty)
            {
                while (true)
                {
                    // Move to the next matching node that is before the top node on the stack in document order
                    if (_filter.MoveToFollowing(_navCurrent, _navStack.Peek()))
                    {
                        // Found match
                        return(true);
                    }

                    // Do not include ancestor nodes as part of the preceding axis
                    _navCurrent.MoveTo(_navStack.Pop());

                    // No more preceding matches possible
                    if (_navStack.IsEmpty)
                    {
                        break;
                    }
                }
            }

            return(false);
        }
Example #2
0
        public bool MoveNext()
        {
            switch (_state)
            {
            case IteratorState.HaveCurrent:
                _state = IteratorState.NeedCurrent;
                return(true);

            case IteratorState.NeedCurrent:
                // Move to next following node which matches
                if (!_filter.MoveToFollowing(_navCurrent, _navEnd))
                {
                    // No more nodes unless ending node matches
                    if (_filter.IsFiltered(_navEnd))
                    {
                        _state = IteratorState.NoNext;
                        return(false);
                    }

                    _navCurrent.MoveTo(_navEnd);
                    _state = IteratorState.NoNext;
                }
                return(true);

            case IteratorState.HaveCurrentNoNext:
                _state = IteratorState.NoNext;
                return(true);
            }

            Debug.Assert(_state == IteratorState.NoNext, "Illegal state: " + _state);
            return(false);
        }
Example #3
0
 public bool MoveNext()
 {
     if (_hasFirst)
     {
         _hasFirst = false;
         return(true);
     }
     return(_filter.MoveToFollowing(_navCurrent, _navEnd));
 }
Example #4
0
        internal static bool MoveFirst(XmlNavigatorFilter filter, XPathNavigator nav)
        {
            // Attributes and namespace nodes include descendants of their owner element in the set of following nodes
            if (nav.NodeType == XPathNodeType.Attribute || nav.NodeType == XPathNodeType.Namespace)
            {
                if (!nav.MoveToParent())
                {
                    // Floating attribute or namespace node that has no following nodes
                    return(false);
                }

                if (!filter.MoveToFollowing(nav, null))
                {
                    // No matching following nodes
                    return(false);
                }
            }
            else
            {
                // XPath spec doesn't include descendants of the input node in the following axis
                if (!nav.MoveToNonDescendant())
                {
                    // No following nodes
                    return(false);
                }

                // If the sibling does not match the node-test, find the next following node that does
                if (filter.IsFiltered(nav))
                {
                    if (!filter.MoveToFollowing(nav, null))
                    {
                        // No matching following nodes
                        return(false);
                    }
                }
            }

            // Success
            return(true);
        }
Example #5
0
        public bool MoveNext()
        {
            if (_needFirst)
            {
                if (!MoveFirst(_filter, _navCurrent))
                {
                    return(false);
                }

                _needFirst = false;
                return(true);
            }

            return(_filter.MoveToFollowing(_navCurrent, null));
        }
Example #6
0
        public IteratorResult MoveNext(XPathNavigator input)
        {
            if (_state != IteratorState.NeedDescendant)
            {
                if (input == null)
                {
                    return(IteratorResult.NoMoreNodes);
                }

                // Descendants of the input node will be duplicates if the input node is in the subtree
                // of the previous root.
                if (_state != IteratorState.NoPrevious && _navRoot.IsDescendant(input))
                {
                    return(IteratorResult.NeedInputNode);
                }

                // Save input node as current node and end of input's tree in navEnd
                _navCurrent = XmlQueryRuntime.SyncToNavigator(_navCurrent, input);
                _navRoot    = XmlQueryRuntime.SyncToNavigator(_navRoot, input);
                _navEnd     = XmlQueryRuntime.SyncToNavigator(_navEnd, input);
                _navEnd.MoveToNonDescendant();

                _state = IteratorState.NeedDescendant;

                // If self node matches, then return it
                if (_orSelf && !_filter.IsFiltered(input))
                {
                    return(IteratorResult.HaveCurrentNode);
                }
            }

            if (_filter.MoveToFollowing(_navCurrent, _navEnd))
            {
                return(IteratorResult.HaveCurrentNode);
            }

            // No more descendants, so transition to NeedCurrent state and get the next input node
            _state = IteratorState.NeedCurrent;
            return(IteratorResult.NeedInputNode);
        }
        /// <summary>
        /// Initialize the PrecedingIterator (no possibility of duplicates).
        /// </summary>
        public void Create(XPathNavigator context, XmlNavigatorFilter filter)
        {
            // Start at root, which is always first node in the document
            this.navCurrent = XmlQueryRuntime.SyncToNavigator(this.navCurrent, context);
            this.navCurrent.MoveToRoot();

            // If root node is not the ending node,
            if (!this.navCurrent.IsSamePosition(context))
            {
                // Push root onto the stack if it is not filtered
                if (!filter.IsFiltered(this.navCurrent))
                {
                    this.stack.Push(this.navCurrent.Clone());
                }

                // Push all matching nodes onto stack
                while (filter.MoveToFollowing(this.navCurrent, context))
                {
                    this.stack.Push(this.navCurrent.Clone());
                }
            }
        }
        /// <summary>
        /// Initialize the PrecedingIterator (no possibility of duplicates).
        /// </summary>
        public void Create(XPathNavigator context, XmlNavigatorFilter filter) {
            // Start at root, which is always first node in the document
            this.navCurrent = XmlQueryRuntime.SyncToNavigator(this.navCurrent, context);
            this.navCurrent.MoveToRoot();

            // If root node is not the ending node,
            if (!this.navCurrent.IsSamePosition(context)) {
                // Push root onto the stack if it is not filtered
                if (!filter.IsFiltered(this.navCurrent))
                    this.stack.Push(this.navCurrent.Clone());

                // Push all matching nodes onto stack
                while (filter.MoveToFollowing(this.navCurrent, context))
                    this.stack.Push(this.navCurrent.Clone());
            }
        }
        /// <summary>
        /// Position "nav" to the matching node which follows it in document order but is not a descendant node.
        /// Return false if this is no such matching node.
        /// </summary>
        internal static bool MoveFirst(XmlNavigatorFilter filter, XPathNavigator nav) {
            // Attributes and namespace nodes include descendants of their owner element in the set of following nodes
            if (nav.NodeType == XPathNodeType.Attribute || nav.NodeType == XPathNodeType.Namespace) {
                if (!nav.MoveToParent()) {
                    // Floating attribute or namespace node that has no following nodes
                    return false;
                }

                if (!filter.MoveToFollowing(nav, null)) {
                    // No matching following nodes
                    return false;
                }
            }
            else {
                // XPath spec doesn't include descendants of the input node in the following axis
                if (!nav.MoveToNonDescendant())
                    // No following nodes
                    return false;

                // If the sibling does not match the node-test, find the next following node that does
                if (filter.IsFiltered(nav)) {
                    if (!filter.MoveToFollowing(nav, null)) {
                        // No matching following nodes
                        return false;
                    }
                }
            }

            // Success
            return true;
        }
Example #10
0
        public IteratorResult MoveNext(XPathNavigator input)
        {
            switch (_state)
            {
            case IteratorState.NeedCandidateCurrent:
                // If there are no more input nodes, then iteration is complete
                if (input == null)
                {
                    return(IteratorResult.NoMoreNodes);
                }

                // Save input node as current node
                _navCurrent = XmlQueryRuntime.SyncToNavigator(_navCurrent, input);

                // Scan for additional input nodes within the same document (since they are after navCurrent in docorder)
                _state = IteratorState.HaveCandidateCurrent;
                return(IteratorResult.NeedInputNode);

            case IteratorState.HaveCandidateCurrent:
                // If there are no more input nodes,
                if (input == null)
                {
                    // Then candidate node has been selected, and there are no further input nodes
                    _state = IteratorState.HaveCurrentNoNext;
                }
                else
                {
                    // If the input node is in the same document as the current node,
                    if (_navCurrent.ComparePosition(input) != XmlNodeOrder.Unknown)
                    {
                        // Then update the current node and get the next input node
                        _navCurrent = XmlQueryRuntime.SyncToNavigator(_navCurrent, input);
                        return(IteratorResult.NeedInputNode);
                    }

                    // Save the input node as navNext
                    _navNext = XmlQueryRuntime.SyncToNavigator(_navNext, input);
                    _state   = IteratorState.HaveCurrentHaveNext;
                }
                PushAncestors();
                break;
            }

            if (!_navStack.IsEmpty)
            {
                while (true)
                {
                    // Move to the next matching node that is before the top node on the stack in document order
                    if (_filter.MoveToFollowing(_navCurrent, _navStack.Peek()))
                    {
                        // Found match
                        return(IteratorResult.HaveCurrentNode);
                    }

                    // Do not include ancestor nodes as part of the preceding axis
                    _navCurrent.MoveTo(_navStack.Pop());

                    // No more preceding matches possible
                    if (_navStack.IsEmpty)
                    {
                        break;
                    }
                }
            }

            if (_state == IteratorState.HaveCurrentNoNext)
            {
                // No more nodes, so iteration is complete
                _state = IteratorState.NeedCandidateCurrent;
                return(IteratorResult.NoMoreNodes);
            }

            // Make next node the current node and start trying to find input node greatest in docorder
            _navCurrent = XmlQueryRuntime.SyncToNavigator(_navCurrent, _navNext);
            _state      = IteratorState.HaveCandidateCurrent;
            return(IteratorResult.HaveCurrentNode);
        }
Example #11
0
        public IteratorResult MoveNext(XPathNavigator input)
        {
            switch (_state)
            {
            case IteratorState.NeedCandidateCurrent:
                // If there are no more input nodes, then iteration is complete
                if (input == null)
                {
                    return(IteratorResult.NoMoreNodes);
                }

                // Save input node as current node
                _navCurrent = XmlQueryRuntime.SyncToNavigator(_navCurrent, input);

                // Still must check next input node to see if is a descendant of this one
                _state = IteratorState.HaveCandidateCurrent;
                return(IteratorResult.NeedInputNode);

            case IteratorState.HaveCandidateCurrent:
                // If there are no more input nodes,
                if (input == null)
                {
                    // Then candidate node has been selected, and there are no further input nodes
                    _state = IteratorState.HaveCurrentNoNext;
                    return(MoveFirst());
                }

                // If input node is in the subtree of the candidate node, then use the input node instead
                if (_navCurrent.IsDescendant(input))
                {
                    goto case IteratorState.NeedCandidateCurrent;
                }

                // Found node on which to perform following scan.  Now skip past all input nodes in the same document.
                _state = IteratorState.HaveCurrentNeedNext;
                goto case IteratorState.HaveCurrentNeedNext;

            case IteratorState.HaveCurrentNeedNext:
                // If there are no more input nodes,
                if (input == null)
                {
                    // Then candidate node has been selected, and there are no further input nodes
                    _state = IteratorState.HaveCurrentNoNext;
                    return(MoveFirst());
                }

                // Skip input node unless it's in a different document than the node on which the following scan was performed
                if (_navCurrent.ComparePosition(input) != XmlNodeOrder.Unknown)
                {
                    return(IteratorResult.NeedInputNode);
                }

                // Next node is in a different document, so save it
                _navNext = XmlQueryRuntime.SyncToNavigator(_navNext, input);
                _state   = IteratorState.HaveCurrentHaveNext;
                return(MoveFirst());
            }

            if (!_filter.MoveToFollowing(_navCurrent, null))
            {
                return(MoveFailed());
            }

            return(IteratorResult.HaveCurrentNode);
        }