Peek() public method

Returns the navigator at the top of the stack without adjusting the stack pointer
public Peek ( ) : XPathNavigator
return System.Xml.XPath.XPathNavigator
Exemplo n.º 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);
        }
Exemplo n.º 2
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);
        }