ComparePosition() public method

public ComparePosition ( XPathNavigator nav ) : XmlNodeOrder
nav XPathNavigator
return XmlNodeOrder
Ejemplo n.º 1
0
        public int Compare(object o1, object o2)
        {
            XPathNavigator nav1 = o1 as XPathNavigator;
            XPathNavigator nav2 = o2 as XPathNavigator;

            if (nav1 == null)
            {
                return(-1);
            }
            if (nav2 == null)
            {
                return(1);
            }
            switch (nav1.ComparePosition(nav2))
            {
            case XmlNodeOrder.Same:
                return(0);

            case XmlNodeOrder.After:
                return(1);

            default:
                return(-1);
            }
        }
Ejemplo n.º 2
0
 internal override void FillStk()
 {
     while ((m_eNext = m_qyInput.advance()) != null)
     {
         bool add = true;
         for (int i = 0; i < _Stk.Count; i++)
         {
             XPathNavigator nav     = _Stk[i] as XPathNavigator;
             XmlNodeOrder   compare = nav.ComparePosition(m_eNext);
             if (compare == XmlNodeOrder.Same)
             {
                 add = false;
                 break;
             }
             if (compare == XmlNodeOrder.Before)
             {
                 _Stk.Insert(i, m_eNext.Clone());
                 add = false;
                 break;
             }
         }
         if (add)
         {
             _Stk.Add(m_eNext.Clone());
         }
     }
     _fillStk = false;
     _count   = _Stk.Count;
 }
        public int Compare(object o1, object o2)
        {
            XPathNavigator xpathNavigator  = o1 as XPathNavigator;
            XPathNavigator xpathNavigator2 = o2 as XPathNavigator;

            if (xpathNavigator == null)
            {
                return(-1);
            }
            if (xpathNavigator2 == null)
            {
                return(1);
            }
            XmlNodeOrder xmlNodeOrder = xpathNavigator.ComparePosition(xpathNavigator2);

            if (xmlNodeOrder == XmlNodeOrder.After)
            {
                return(1);
            }
            if (xmlNodeOrder != XmlNodeOrder.Same)
            {
                return(-1);
            }
            return(0);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Add a node indexed by the specified key value.
        /// </summary>
        public void Add(string key, XPathNavigator navigator) {
            XmlQueryNodeSequence seq;

            if (!this.table.TryGetValue(key, out seq)) {
                // Create a new sequence and add it to the index
                seq = new XmlQueryNodeSequence();
                seq.AddClone(navigator);
                this.table.Add(key, seq);
            }
            else {
                // The nodes are guaranteed to be added in document order with possible duplicates.
                // Add node to the existing sequence if it differs from the last one.
                Debug.Assert(navigator.ComparePosition(seq[seq.Count - 1]) >= 0, "Index nodes must be added in document order");
                if (!navigator.IsSamePosition(seq[seq.Count - 1])) {
                    seq.AddClone(navigator);
                }
            }
        }
Ejemplo n.º 5
0
 private void AddResult(XPathNavigator current)
 {
     for (int i = 0; i < _ResultStk.Count; i++)
     {
         XPathNavigator nav     = _ResultStk[i] as XPathNavigator;
         XmlNodeOrder   compare = nav.ComparePosition(current);
         if (compare == XmlNodeOrder.Same)
         {
             return;
         }
         if (compare == XmlNodeOrder.Before)
         {
             _ResultStk.Insert(i, current);
             return;
         }
     }
     _ResultStk.Add(current);
 }
Ejemplo n.º 6
0
        void NotVisited(XPathNavigator current)
        {
            XmlNodeOrder compare;

            for (int i = 0; i < _stack.Count; i++)
            {
                XPathNavigator nav = _stack[i] as XPathNavigator;
                compare = nav.ComparePosition(current);
                if (compare == XmlNodeOrder.Same)
                {
                    return;
                }
                if (compare == XmlNodeOrder.Before)
                {
                    _stack.Insert(i, current.Clone());
                    return;
                }
            }
            _stack.Add(current.Clone());
        }
Ejemplo n.º 7
0
        void AddToStack(XPathNavigator current)
        {
            XmlNodeOrder compare;

            for (int i = 0; i < ElementList.Count; i++)
            {
                XPathNavigator nav = ElementList[i] as XPathNavigator;
                compare = nav.ComparePosition(current);
                if (compare == XmlNodeOrder.Same)
                {
                    return;
                }
                if (compare == XmlNodeOrder.Before)
                {
                    ElementList.Insert(i, current.Clone());
                    return;
                }
            }
            ElementList.Add(current.Clone());
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Position this iterator to the next preceding node in document order.  Discard all input nodes
        /// that are followed by another input node in the same document.  This leaves one node per document from
        /// which the complete set of preceding nodes can be derived without possibility of duplicates.
        /// Return IteratorResult.NeedInputNode if the next input node needs to be fetched first.  Return
        /// IteratorResult.HaveCurrent if the Current property is set to the next node in the iteration.
        /// </summary>
        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;
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Position this iterator to the next following node.  Prune by finding the first input node in
        /// document order that has no other input nodes in its subtree.  All other input nodes should be
        /// discarded.  Return IteratorResult.NeedInputNode if the next input node needs to be fetched
        /// first.  Return IteratorResult.HaveCurrent if the Current property is set to the next node in the
        /// iteration.
        /// </summary>
        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;
        }
Ejemplo n.º 10
0
 public static XmlNodeOrder CompareNodes(XPathNavigator l, XPathNavigator r)
 {
     XmlNodeOrder cmp = l.ComparePosition(r);
     if (cmp == XmlNodeOrder.Unknown)
     {
         XPathNavigator copy = l.Clone();
         copy.MoveToRoot();
         string baseUriL = copy.BaseURI;
         if (!copy.MoveTo(r))
         {
             copy = r.Clone();
         }
         copy.MoveToRoot();
         string baseUriR = copy.BaseURI;
         int cmpBase = string.CompareOrdinal(baseUriL, baseUriR);
         cmp = (
             cmpBase < 0 ? XmlNodeOrder.Before :
             cmpBase > 0 ? XmlNodeOrder.After :
             /*default*/   XmlNodeOrder.Unknown
         );
     }
     return cmp;
 }
 private static void AddKeyValue(Hashtable keyTable, String key, XPathNavigator value, bool checkDuplicates) {
     ArrayList list = (ArrayList)keyTable[key];
     if (list == null) {
         list = new ArrayList();
         keyTable.Add(key, list);
     } else {
         Debug.Assert(
             value.ComparePosition((XPathNavigator) list[list.Count - 1]) != XmlNodeOrder.Before,
             "The way we traversing nodes should garantees node-order"
         );
         if (checkDuplicates) {
             // it's posible that this value already was ----osiated with current node
             // but if this happened the node is last in the list of values.
             if (value.ComparePosition((XPathNavigator) list[list.Count - 1]) == XmlNodeOrder.Same) {
                 return;
             }
         } else {
             Debug.Assert(
                 value.ComparePosition((XPathNavigator) list[list.Count - 1]) != XmlNodeOrder.Same,
                 "checkDuplicates == false : We can't have duplicates"
             );
         }
     }
     list.Add(value.Clone());
 }
Ejemplo n.º 12
0
 private void AddResult(ArrayList ResultList, XPathNavigator nav) {
     int count = ResultList.Count;
     for(int i = 0; i< count; i++ ) {
         XmlNodeOrder docOrder = nav.ComparePosition(((XPathNavigator)ResultList[i] ));
         if (docOrder == XmlNodeOrder.Same){
             return;
         }
         if (docOrder == XmlNodeOrder.Before) {
             ResultList.Insert(i, nav.Clone());
             return;
         }
     }
     ResultList.Add(nav.Clone());
 }
 public static XmlNodeOrder CompareNodes(XPathNavigator l, XPathNavigator r)
 {
     XmlNodeOrder order = l.ComparePosition(r);
     if (order != XmlNodeOrder.Unknown)
     {
         return order;
     }
     XPathNavigator navigator = l.Clone();
     navigator.MoveToRoot();
     string baseURI = navigator.BaseURI;
     if (!navigator.MoveTo(r))
     {
         navigator = r.Clone();
     }
     navigator.MoveToRoot();
     string strB = navigator.BaseURI;
     int num = string.CompareOrdinal(baseURI, strB);
     return ((num < 0) ? XmlNodeOrder.Before : ((num > 0) ? XmlNodeOrder.After : XmlNodeOrder.Unknown));
 }
Ejemplo n.º 14
0
        /// <summary>
        /// Checks an XPathNavigator object to see if it's already in the dependency
        /// map. Contains won't work with XPathNavigator objects that point
        /// to the same node, you see.
        /// </summary>
        /// <param name="node">The node to test.</param>
        /// <returns>true if it's on the list.</returns>
        private bool IsInDependenciesMap(XPathNavigator node)
        {
            foreach (DependencyList next in this.dependencyMap)
            {
                if (node.ComparePosition(next.Node) == XmlNodeOrder.Same)
                {
                    return true;
                }
            }

            return false;
        }
Ejemplo n.º 15
0
        private bool IsContextUsed(XPathNavigator contextNode)
        {
            foreach (XPathNavigator nav in this.usedContext)
            {
                if (contextNode.ComparePosition(nav) == System.Xml.XmlNodeOrder.Same)
                {
                    return true;
                }
            }

            return false;
        }