IsSamePosition() public abstract method

public abstract IsSamePosition ( XPathNavigator other ) : bool
other XPathNavigator
return bool
Ejemplo n.º 1
0
        /// <include file='doc\XPathNavigator.uex' path='docs/doc[@for="XPathNavigator.ComparePosition"]/*' />
        public virtual XmlNodeOrder ComparePosition(XPathNavigator nav)
        {
            if (IsSamePosition(nav))
            {
                return(XmlNodeOrder.Same);
            }

            XPathNavigator n1 = this.Clone();
            XPathNavigator n2 = nav.Clone();

            int depth1 = GetDepth(n1.Clone());
            int depth2 = GetDepth(n2.Clone());

            if (depth1 > depth2)
            {
                while (depth1 > depth2)
                {
                    n1.MoveToParent();
                    depth1--;
                }
                if (n1.IsSamePosition(n2))
                {
                    return(XmlNodeOrder.After);
                }
            }

            if (depth2 > depth1)
            {
                while (depth2 > depth1)
                {
                    n2.MoveToParent();
                    depth2--;
                }
                if (n1.IsSamePosition(n2))
                {
                    return(XmlNodeOrder.Before);
                }
            }

            XPathNavigator parent1 = n1.Clone();
            XPathNavigator parent2 = n2.Clone();

            while (true)
            {
                if (!parent1.MoveToParent() || !parent2.MoveToParent())
                {
                    return(XmlNodeOrder.Unknown);
                }

                if (parent1.IsSamePosition(parent2))
                {
                    return(CompareSiblings(n1, n2));
                }

                n1.MoveToParent();
                n2.MoveToParent();
            }
        }
Ejemplo n.º 2
0
        private XmlNodeOrder CompareSiblings(XPathNavigator n1, XPathNavigator n2)
        {
            bool attr1 = n1.NodeType == XPathNodeType.Attribute;
            bool attr2 = n2.NodeType == XPathNodeType.Attribute;
            bool ns1   = n1.NodeType == XPathNodeType.Namespace;
            bool ns2   = n2.NodeType == XPathNodeType.Namespace;

            if (!ns1 && !ns2 && !attr1 && !attr2)
            {
                while (n1.MoveToNext())
                {
                    if (n1.IsSamePosition(n2))
                    {
                        return(XmlNodeOrder.Before);
                    }
                }
                return(XmlNodeOrder.After);
            }
            if (attr1 && attr2)
            {
                while (n1.MoveToNextAttribute())
                {
                    if (n1.IsSamePosition(n2))
                    {
                        return(XmlNodeOrder.Before);
                    }
                }
                return(XmlNodeOrder.After);
            }
            if (attr1)
            {
                return(XmlNodeOrder.After);
            }
            if (attr2)
            {
                return(XmlNodeOrder.Before);
            }
            if (ns1 && ns2)
            {
                while (n1.MoveToNextNamespace())
                {
                    if (n1.IsSamePosition(n2))
                    {
                        return(XmlNodeOrder.Before);
                    }
                }
                return(XmlNodeOrder.After);
            }
            if (ns1)
            {
                return(XmlNodeOrder.After);
            }
            Debug.Assert(ns2);
            return(XmlNodeOrder.Before);
        }
        bool IEqualityComparer.Equals(object o1, object o2)
        {
            XPathNavigator xpathNavigator  = o1 as XPathNavigator;
            XPathNavigator xpathNavigator2 = o2 as XPathNavigator;

            return(xpathNavigator != null && xpathNavigator2 != null && xpathNavigator.IsSamePosition(xpathNavigator2));
        }
Ejemplo n.º 4
0
        public SortedIterator(BaseIterator iter) : base(iter.NamespaceManager)
        {
            this.list = new ArrayList();
            while (iter.MoveNext())
            {
                XPathNavigator xpathNavigator = iter.Current;
                this.list.Add(xpathNavigator.Clone());
            }
            if (this.list.Count == 0)
            {
                return;
            }
            XPathNavigator xpathNavigator2 = (XPathNavigator)this.list[0];

            this.list.Sort(XPathNavigatorComparer.Instance);
            for (int i = 1; i < this.list.Count; i++)
            {
                XPathNavigator xpathNavigator3 = (XPathNavigator)this.list[i];
                if (xpathNavigator2.IsSamePosition(xpathNavigator3))
                {
                    this.list.RemoveAt(i);
                    i--;
                }
                else
                {
                    xpathNavigator2 = xpathNavigator3;
                }
            }
        }
Ejemplo n.º 5
0
        public SortedIterator(BaseIterator iter) : base(iter.NamespaceManager)
        {
            list = new ArrayList();
            while (iter.MoveNext())
            {
                list.Add(iter.Current.Clone());
            }

            // sort
            if (list.Count == 0)
            {
                return;
            }
            XPathNavigator prev = (XPathNavigator)list [0];

            list.Sort(XPathNavigatorComparer.Instance);
            for (int i = 1; i < list.Count; i++)
            {
                XPathNavigator n = (XPathNavigator)list [i];
                if (prev.IsSamePosition(n))
                {
                    list.RemoveAt(i);
                    i--;
                }
                else
                {
                    prev = n;
                }
            }
        }
Ejemplo n.º 6
0
        override internal XPathNavigator MatchNode(XPathNavigator current)
        {
            XPathNavigator context = _child.MatchNode(current);

            if (context == null)
            {
                return(null);
            }
            context = m_qyInput.MatchNode(context);
            if (context == null)
            {
                return(null);
            }
            setContext(context.Clone());
            XPathNavigator result = advance();

            while (result != null)
            {
                if (result.IsSamePosition(current))
                {
                    return(context);
                }
                result = advance();
            }
            return(null);
        }
Ejemplo n.º 7
0
        private void DeleteChildren()
        {
            switch (NodeType)
            {
            case XPathNodeType.Namespace:
                throw new InvalidOperationException("Removing namespace node content is not supported.");

            case XPathNodeType.Attribute:
                return;

            case XPathNodeType.Text:
            case XPathNodeType.SignificantWhitespace:
            case XPathNodeType.Whitespace:
            case XPathNodeType.ProcessingInstruction:
            case XPathNodeType.Comment:
                DeleteSelf();
                return;
            }
            if (!HasChildren)
            {
                return;
            }
            XPathNavigator nav = Clone();

            nav.MoveToFirstChild();
            while (!nav.IsSamePosition(this))
            {
                nav.DeleteSelf();
            }
        }
Ejemplo n.º 8
0
        bool IEqualityComparer.Equals(object o1, object o2)
        {
            XPathNavigator nav1 = o1 as XPathNavigator;
            XPathNavigator nav2 = o2 as XPathNavigator;

            return(nav1 != null && nav2 != null && nav1.IsSamePosition(nav2));
        }
Ejemplo n.º 9
0
        bool IEqualityComparer.Equals(object obj1, object obj2)
        {
            XPathNavigator navigator = obj1 as XPathNavigator;
            XPathNavigator other     = obj2 as XPathNavigator;

            return(((navigator != null) && (other != null)) && navigator.IsSamePosition(other));
        }
Ejemplo n.º 10
0
 private int InStk(XPathNavigator temp){
     int flag = 0;
     for(int i= 0;i< _AncestorStk.Count; i++){
         if (temp.IsSamePosition((XPathNavigator)_AncestorStk[i])){
             if (i == _AncestorStk.Count - 1)
                 flag = 2;
             _AncestorStk.RemoveAt(i);
             return flag;
         }
     }
     return 1;
 }
Ejemplo n.º 11
0
        /// <summary>See <see cref="IMatchedNodes.IsMatched"/>.</summary>
        public bool IsMatched(System.Xml.XPath.XPathNavigator node)
        {
            foreach (XPathNavigator nav in _matched)
            {
                if (node.IsSamePosition(nav))
                {
                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 12
0
        internal override XPathNavigator MatchNode(XPathNavigator context)
        {
            setContext(context);
            XPathNavigator result = null;

            while ((result = advance()) != null)
            {
                if (result.IsSamePosition(context))
                {
                    return(context);
                }
            }
            return(null);
        }
Ejemplo n.º 13
0
        public bool Equals(object o1, object o2)
        {
            XPathNavigator nav1 = o1 as XPathNavigator;
            XPathNavigator nav2 = o2 as XPathNavigator;

            if (nav1 != null && nav2 != null)
            {
                return(nav1.IsSamePosition(nav2));
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 14
0
        bool IEqualityComparer.Equals(Object obj1, Object obj2)
        {
            XPathNavigator nav1 = obj1 as XPathNavigator;
            XPathNavigator nav2 = obj2 as XPathNavigator;

            if ((nav1 != null) && (nav2 != null))
            {
                if (nav1.IsSamePosition(nav2))
                {
                    return(true);
                }
            }
            return(false);
        }
Ejemplo n.º 15
0
 /// <include file='doc\XPathNavigator.uex' path='docs/doc[@for="XPathNavigator.IsDescendant"]/*' />
 public virtual bool IsDescendant(XPathNavigator nav)
 {
     if (nav != null)
     {
         XPathNavigator temp = nav.Clone();
         while (temp.MoveToParent())
         {
             if (temp.IsSamePosition(this))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Ejemplo n.º 16
0
        private bool NotVisited(XPathNavigator nav)
        {
            XPathNavigator nav1 = nav.Clone();

            nav1.MoveToParent();
            for (int i = 0; i < _ParentStk.Count; i++)
            {
                if (nav1.IsSamePosition((XPathNavigator)_ParentStk[i]))
                {
                    return(false);
                }
            }
            _ParentStk.Add(nav1);
            return(true);
        }
Ejemplo n.º 17
0
        virtual bool MoveToFollowing(XPathNodeType type,
                                     XPathNavigator end)
        {
            if (type == XPathNodeType.Root)
            {
                return(false);                // will never match
            }
            XPathNavigator nav = Clone();

            switch (nav.NodeType)
            {
            case XPathNodeType.Attribute:
            case XPathNodeType.Namespace:
                nav.MoveToParent();
                break;
            }
            do
            {
                if (!nav.MoveToFirstChild())
                {
                    do
                    {
                        if (!nav.MoveToNext())
                        {
                            if (!nav.MoveToParent())
                            {
                                return(false);
                            }
                        }
                        else
                        {
                            break;
                        }
                    } while (true);
                }
                if (end != null && end.IsSamePosition(nav))
                {
                    return(false);
                }
                if (type == XPathNodeType.All || nav.NodeType == type)
                {
                    MoveTo(nav);
                    return(true);
                }
            } while (true);
        }
Ejemplo n.º 18
0
        internal override XPathNavigator MatchNode(XPathNavigator navigator)
        {
            if (_Name != "key" && _Prefix != String.Empty)
            {
                throw new XPathException(Res.Xp_InvalidPattern);
            }
            InvokeFunction(navigator);
            XPathNavigator nav = null;

            while ((nav = _ResultQuery.advance()) != null)
            {
                if (nav.IsSamePosition(navigator))
                {
                    return(nav);
                }
            }
            return(nav);
        }
Ejemplo n.º 19
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.º 20
0
        private int InStk(XPathNavigator temp)
        {
            int flag = 0;

            for (int i = 0; i < _AncestorStk.Count; i++)
            {
                if (temp.IsSamePosition((XPathNavigator)_AncestorStk[i]))
                {
                    if (i == _AncestorStk.Count - 1)
                    {
                        flag = 2;
                    }
                    _AncestorStk.RemoveAt(i);
                    return(flag);
                }
            }
            return(1);
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Add a node indexed by the specified key value.
        /// </summary>
        public void Add(string key, XPathNavigator navigator) {
            XmlQueryNodeSequence seq = (XmlQueryNodeSequence) this.table[key];

            if (seq == null) {
                // Create a new sequence and add it to the index
                seq = new XmlQueryNodeSequence();
                seq.AddClone(navigator);
                this.table.Add(key, seq);
            }
            else {
                // Add node to existing sequence; don't add if it already there
                for (int i = 0; i < seq.Count; i++) {
                    if (navigator.IsSamePosition(seq[i]))
                        return;
                }

                seq.AddClone(navigator);
            }
        }
Ejemplo n.º 22
0
        protected XPathNavigator MatchNode(XPathNavigator current, IQuery query)
        {
            XPathNavigator context;

            if (current != null)
            {
                context = query.MatchNode(current);
                if (context != null)
                {
                    if (_opnd.ReturnType() == XPathResultType.Number)
                    {
                        if (_opnd.getName() == Querytype.Constant)
                        {
                            XPathNavigator result = current.Clone();

                            int i = 0;
                            if (query.getName() == Querytype.Child)
                            {
                                result.MoveToParent();
                                result.MoveToFirstChild();
                                while (true)
                                {
                                    if (((ChildrenQuery)query).matches(result))
                                    {
                                        i++;
                                        if (current.IsSamePosition(result))
                                        {
                                            if (XmlConvert.ToXPathDouble(_opnd.getValue(current, null)) == i)
                                            {
                                                return(context);
                                            }
                                            else
                                            {
                                                return(null);
                                            }
                                        }
                                    }
                                    if (!result.MoveToNext())
                                    {
                                        return(null);
                                    }
                                }
                            }
                            if (query.getName() == Querytype.Attribute)
                            {
                                result.MoveToParent();
                                result.MoveToFirstAttribute();
                                while (true)
                                {
                                    if (((AttributeQuery)query).matches(result))
                                    {
                                        i++;
                                    }
                                    if (current.IsSamePosition(result))
                                    {
                                        if (XmlConvert.ToXPathDouble(_opnd.getValue(current, null)) == i)
                                        {
                                            return(context);
                                        }
                                        else
                                        {
                                            return(null);
                                        }
                                    }
                                    if (!result.MoveToNextAttribute())
                                    {
                                        return(null);
                                    }
                                }
                            }
                        }
                        else
                        {
                            setContext(context.Clone());
                            XPathNavigator result = advance();
                            while (result != null)
                            {
                                if (result.IsSamePosition(current))
                                {
                                    return(context);
                                }
                                result = advance();
                            }
                        }
                    }
                    if (_opnd.ReturnType() == XPathResultType.NodeSet)
                    {
                        _opnd.setContext(current);
                        if (_opnd.advance() != null)
                        {
                            return(context);
                        }
                        else
                        {
                            return(null);
                        }
                    }
                    if (_opnd.ReturnType() == XPathResultType.Boolean)
                    {
                        if (noPosition)
                        {
                            if ((bool)_opnd.getValue(current, null))
                            {
                                return(context);
                            }
                            return(null);
                        }
                        setContext(context.Clone());
                        XPathNavigator result = advance();
                        while (result != null)
                        {
                            if (result.IsSamePosition(current))
                            {
                                return(context);
                            }
                            result = advance();
                        }
                        return(null);
                    }
                    if (_opnd.ReturnType() == XPathResultType.String)
                    {
                        if (_opnd.getValue(context, null).ToString().Length > 0)
                        {
                            return(context);
                        }
                        else
                        {
                            return(null);
                        }
                    }
                }
                else
                {
                    return(null);
                }
            }
            return(null);
        }
Ejemplo n.º 23
0
        virtual bool MoveToFollowing(string localName,
                                     string namespaceURI, XPathNavigator end)
        {
            if (localName == null)
            {
                throw new ArgumentNullException("localName");
            }
            if (namespaceURI == null)
            {
                throw new ArgumentNullException("namespaceURI");
            }
            localName = NameTable.Get(localName);
            if (localName == null)
            {
                return(false);
            }
            namespaceURI = NameTable.Get(namespaceURI);
            if (namespaceURI == null)
            {
                return(false);
            }

            XPathNavigator nav = Clone();

            switch (nav.NodeType)
            {
            case XPathNodeType.Attribute:
            case XPathNodeType.Namespace:
                nav.MoveToParent();
                break;
            }
            do
            {
                if (!nav.MoveToFirstChild())
                {
                    do
                    {
                        if (!nav.MoveToNext())
                        {
                            if (!nav.MoveToParent())
                            {
                                return(false);
                            }
                        }
                        else
                        {
                            break;
                        }
                    } while (true);
                }
                if (end != null && end.IsSamePosition(nav))
                {
                    return(false);
                }
                if (object.ReferenceEquals(localName, nav.LocalName) &&
                    object.ReferenceEquals(namespaceURI, nav.NamespaceURI))
                {
                    MoveTo(nav);
                    return(true);
                }
            } while (true);
        }
Ejemplo n.º 24
0
        public virtual XmlNodeOrder ComparePosition(XPathNavigator nav)
        {
            if (IsSamePosition(nav))
            {
                return(XmlNodeOrder.Same);
            }

            if (IsDescendant(nav))
            {
                return(XmlNodeOrder.Before);
            }
            else if (nav.IsDescendant(this))
            {
                return(XmlNodeOrder.After);
            }

            XPathNavigator copy  = this.Clone();
            XPathNavigator other = nav.Clone();

            /* now, it gets expensive - we find the
             * closest common ancestor. But these two
             * might be from totally different places.
             *
             * Someone should re-implement this somewhere,
             * so that it is faster for XmlDocument.
             */
            int common     = 0;
            int otherDepth = 0;
            int copyDepth  = 0;

            copy.MoveToRoot();
            other.MoveToRoot();

            if (!copy.IsSamePosition(other))
            {
                return(XmlNodeOrder.Unknown);
            }

            /* what do you think ? I'm made of GC space ? */
            copy.MoveTo(this);
            other.MoveTo(nav);

            while (other.MoveToParent())
            {
                otherDepth++;
            }

            while (copy.MoveToParent())
            {
                copyDepth++;
            }

            common = (otherDepth > copyDepth) ? copyDepth : otherDepth;

            other.MoveTo(nav);
            copy.MoveTo(this);

            // traverse both till you get to depth == common
            for (; otherDepth > common; otherDepth--)
            {
                other.MoveToParent();
            }
            for (; copyDepth > common; copyDepth--)
            {
                copy.MoveToParent();
            }

            other.MoveTo(nav);
            copy.MoveTo(this);

            XPathNavigator copy1  = copy.Clone();
            XPathNavigator other1 = other.Clone();

            while (copy.IsSamePosition(other))
            {
                copy1.MoveTo(copy);
                other1.MoveTo(other);

                copy.MoveToParent();
                other.MoveToParent();
            }

            copy.MoveTo(copy1);
            other.MoveTo(other1);

            // Now copy & other are siblings and can be compared
            while (copy.MoveToNext())
            {
                if (copy.IsSamePosition(other))
                {
                    return(XmlNodeOrder.Before);
                }
            }

            return(XmlNodeOrder.After);
        }
Ejemplo n.º 25
0
        public override XPathNavigator MatchNode(XPathNavigator current) {
            XPathNavigator context;
            if (current == null) {
                return null;
            }
            context = qyInput.MatchNode(current);

            if (context != null) {
                // In this switch we process some special case in wich we can calculate predicate faster then in generic case
                switch (cond.StaticType) {
                case XPathResultType.Number:
                    OperandQuery operand = cond as OperandQuery;
                    if (operand != null) {
                        double val = (double)operand.val;
                        ChildrenQuery childrenQuery = qyInput as ChildrenQuery;
                        if (childrenQuery != null) { // foo[2], but not foo[expr][2]
                            XPathNavigator result = current.Clone();
                            result.MoveToParent();
                            int i = 0;
                            result.MoveToFirstChild();
                            do {
                                if (childrenQuery.matches(result)) {
                                    i++;
                                    if (current.IsSamePosition(result)) {
                                        return val == i ? context : null;
                                    }
                                }
                            } while (result.MoveToNext());
                            return null;
                        }
                        AttributeQuery attributeQuery = qyInput as AttributeQuery;
                        if (attributeQuery != null) {// @foo[3], but not @foo[expr][2]
                            XPathNavigator result = current.Clone();
                            result.MoveToParent();
                            int i = 0;
                            result.MoveToFirstAttribute();
                            do {
                                if (attributeQuery.matches(result)) {
                                    i++;
                                    if (current.IsSamePosition(result)) {
                                        return val == i ? context : null;
                                    }
                                }
                            } while (result.MoveToNextAttribute());
                            return null;
                        }
                    }
                    break;
                case XPathResultType.NodeSet:
                    cond.Evaluate(new XPathSingletonIterator(current, /*moved:*/true));
                    return (cond.Advance() != null) ? context : null;
                case XPathResultType.Boolean:
                    if (noPosition) {
                        return ((bool)cond.Evaluate(new XPathSingletonIterator(current, /*moved:*/true))) ? context : null;
                    }
                    break;
                case XPathResultType.String:
                    if (noPosition) {
                        return (((string)cond.Evaluate(new XPathSingletonIterator(current, /*moved:*/true))).Length != 0) ? context : null;
                    }
                    break;
                case XPathResultType_Navigator:
                    return context;
                default:
                    return null;
                }
                /* Generic case */ {
                    Evaluate(new XPathSingletonIterator(context, /*moved:*/true));
                    XPathNavigator result;
                    while ((result = Advance()) != null) {
                        if (result.IsSamePosition(current)) {
                            return context;
                        }
                    }
                }
            }
            return null;
        }
Ejemplo n.º 26
0
        /// <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
            _navCurrent = XmlQueryRuntime.SyncToNavigator(_navCurrent, context);
            _navCurrent.MoveToRoot();
            _stack.Reset();

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

                // Push all matching nodes onto stack
                while (filter.MoveToFollowing(_navCurrent, context))
                    _stack.Push(_navCurrent.Clone());
            }
        }
Ejemplo n.º 27
0
        protected XPathNavigator MatchNode(XPathNavigator current, IQuery query) {
            XPathNavigator context;
            if (current != null) {
                context = query.MatchNode(current);
                if (context != null) {
                    if (_opnd.ReturnType() == XPathResultType.Number) {
                        if (_opnd.getName() == Querytype.Constant) {
                            XPathNavigator result = current.Clone();

                            int i=0;
                            if (query.getName() == Querytype.Child) {
                                result.MoveToParent();
                                result.MoveToFirstChild();
                                while (true) {
                                    if (((ChildrenQuery)query).matches(result)){
                                        i++;
                                    if (current.IsSamePosition(result))
                                        if (XmlConvert.ToXPathDouble(_opnd.getValue(current, null)) ==  i)
                                            return context;
                                        else
                                            return null;
                                    }        
                                    if (!result.MoveToNext())
                                        return null;

                                }
                            }
                            if (query.getName() == Querytype.Attribute) {
                                result.MoveToParent();
                                result.MoveToFirstAttribute();
                                while (true) {
                                    if (((AttributeQuery)query).matches(result))
                                        i++;
                                    if (current.IsSamePosition(result))
                                        if (XmlConvert.ToXPathDouble(_opnd.getValue(current, null)) == i)
                                            return context;
                                        else
                                            return null;
                                    if (!result.MoveToNextAttribute())
                                        return null;
                         
                                }
                            }
                        }
                        else {
                            setContext(context.Clone());
                            XPathNavigator result = advance();
                            while (result != null) {
                                if (result.IsSamePosition(current))
                                    return context;
                                result = advance();
                            }
                        }

                    }
                    if (_opnd.ReturnType() == XPathResultType.NodeSet) {
                        _opnd.setContext(current); 
                        if (_opnd.advance() != null)
                            return context;
                        else
                            return null;
                    }
                    if (_opnd.ReturnType() == XPathResultType.Boolean) {
                        if (noPosition) {
                            if ((bool)_opnd.getValue(current, null)) {
                                return context;
                            }
                            return null;
                        }
                        setContext(context.Clone());
                        XPathNavigator result = advance();
                        while (result != null) {
                            if (result.IsSamePosition(current))
                                return context;
                            result = advance();
                        }
                        return null;
                    }
                    if (_opnd.ReturnType() == XPathResultType.String)
                        if (_opnd.getValue(context, null).ToString().Length >0)
                            return context;
                        else
                            return null;

                }
                else
                    return null;
            }
            return null;
        } 
 public virtual bool IsDescendant(XPathNavigator nav)
 {
     if (nav != null)
     {
         nav = nav.Clone();
         while (nav.MoveToParent())
         {
             if (nav.IsSamePosition(this))
             {
                 return true;
             }
         }
     }
     return false;
 }
		virtual bool MoveToFollowing (XPathNodeType type,
			XPathNavigator end)
		{
			if (type == XPathNodeType.Root)
				return false; // will never match
			XPathNavigator nav = Clone ();
			switch (nav.NodeType) {
			case XPathNodeType.Attribute:
			case XPathNodeType.Namespace:
				nav.MoveToParent ();
				break;
			}
			do {
				if (!nav.MoveToFirstChild ()) {
					do {
						if (!nav.MoveToNext ()) {
							if (!nav.MoveToParent ())
								return false;
						}
						else
							break;
					} while (true);
				}
				if (end != null && end.IsSamePosition (nav))
					return false;
				if (type == XPathNodeType.All || nav.NodeType == type) {
					MoveTo (nav);
					return true;
				}
			} while (true);
		}
Ejemplo n.º 30
0
        /// <summary>
        /// Initialize the NodeRangeIterator (no possibility of duplicates).
        /// </summary>
        public void Create(XPathNavigator start, XmlNavigatorFilter filter, XPathNavigator end) {
            // Save start node as current node and save ending node
            this.navCurrent = XmlQueryRuntime.SyncToNavigator(this.navCurrent, start);
            this.navEnd = XmlQueryRuntime.SyncToNavigator(this.navEnd, end);
            this.filter = filter;

            if (start.IsSamePosition(end)) {
                // Start is end, so only return node if it is not filtered
                this.state = !filter.IsFiltered(start) ? IteratorState.HaveCurrentNoNext : IteratorState.NoNext;
            }
            else {
                // Return nodes until end is reached
                this.state = !filter.IsFiltered(start) ? IteratorState.HaveCurrent : IteratorState.NeedCurrent;
            }
        }
Ejemplo n.º 31
0
        public virtual XmlNodeOrder ComparePosition(XPathNavigator nav)
        {
            if (IsSamePosition(nav))
            {
                return(XmlNodeOrder.Same);
            }

            // quick check for direct descendant
            if (IsDescendant(nav))
            {
                return(XmlNodeOrder.Before);
            }

            // quick check for direct ancestor
            if (nav.IsDescendant(this))
            {
                return(XmlNodeOrder.After);
            }

            XPathNavigator nav1 = Clone();
            XPathNavigator nav2 = nav.Clone();

            // check if document instance is the same.
            nav1.MoveToRoot();
            nav2.MoveToRoot();
            if (!nav1.IsSamePosition(nav2))
            {
                return(XmlNodeOrder.Unknown);
            }
            nav1.MoveTo(this);
            nav2.MoveTo(nav);

            int depth1 = 0;

            while (nav1.MoveToParent())
            {
                depth1++;
            }
            nav1.MoveTo(this);
            int depth2 = 0;

            while (nav2.MoveToParent())
            {
                depth2++;
            }
            nav2.MoveTo(nav);

            // find common parent depth
            int common = depth1;

            for (; common > depth2; common--)
            {
                nav1.MoveToParent();
            }
            for (int i = depth2; i > common; i--)
            {
                nav2.MoveToParent();
            }
            while (!nav1.IsSamePosition(nav2))
            {
                nav1.MoveToParent();
                nav2.MoveToParent();
                common--;
            }

            // For each this and target, move to the node that is
            // ancestor of the node and child of the common parent.
            nav1.MoveTo(this);
            for (int i = depth1; i > common + 1; i--)
            {
                nav1.MoveToParent();
            }
            nav2.MoveTo(nav);
            for (int i = depth2; i > common + 1; i--)
            {
                nav2.MoveToParent();
            }

            // Those children of common parent are comparable.
            // namespace nodes precede to attributes, and they
            // precede to other nodes.
            if (nav1.NodeType == XPathNodeType.Namespace)
            {
                if (nav2.NodeType != XPathNodeType.Namespace)
                {
                    return(XmlNodeOrder.Before);
                }
                while (nav1.MoveToNextNamespace())
                {
                    if (nav1.IsSamePosition(nav2))
                    {
                        return(XmlNodeOrder.Before);
                    }
                }
                return(XmlNodeOrder.After);
            }
            if (nav2.NodeType == XPathNodeType.Namespace)
            {
                return(XmlNodeOrder.After);
            }
            if (nav1.NodeType == XPathNodeType.Attribute)
            {
                if (nav2.NodeType != XPathNodeType.Attribute)
                {
                    return(XmlNodeOrder.Before);
                }
                while (nav1.MoveToNextAttribute())
                {
                    if (nav1.IsSamePosition(nav2))
                    {
                        return(XmlNodeOrder.Before);
                    }
                }
                return(XmlNodeOrder.After);
            }
            while (nav1.MoveToNext())
            {
                if (nav1.IsSamePosition(nav2))
                {
                    return(XmlNodeOrder.Before);
                }
            }
            return(XmlNodeOrder.After);
        }
Ejemplo n.º 32
0
        // XPath based comparison for namespaces, attributes and other 
        // items with the same parent element.
        //
        //                 n2
        //                 namespace(0)    attribute(-1)   other(-2)
        // n1
        // namespace(0)    ?(0)            before(-1)      before(-2)
        // attribute(1)    after(1)        ?(0)            before(-1)
        // other    (2)    after(2)        after(1)        ?(0)
        private static XmlNodeOrder CompareSiblings(XPathNavigator n1, XPathNavigator n2)
        {
            int cmp = 0;

#if DEBUG
            Debug.Assert(!n1.IsSamePosition(n2));
            XPathNavigator p1 = n1.Clone(), p2 = n2.Clone();
            Debug.Assert(p1.MoveToParent() && p2.MoveToParent() && p1.IsSamePosition(p2));
#endif
            switch (n1.NodeType)
            {
                case XPathNodeType.Namespace:
                    break;
                case XPathNodeType.Attribute:
                    cmp += 1;
                    break;
                default:
                    cmp += 2;
                    break;
            }
            switch (n2.NodeType)
            {
                case XPathNodeType.Namespace:
                    if (cmp == 0)
                    {
                        while (n1.MoveToNextNamespace())
                        {
                            if (n1.IsSamePosition(n2))
                            {
                                return XmlNodeOrder.Before;
                            }
                        }
                    }
                    break;
                case XPathNodeType.Attribute:
                    cmp -= 1;
                    if (cmp == 0)
                    {
                        while (n1.MoveToNextAttribute())
                        {
                            if (n1.IsSamePosition(n2))
                            {
                                return XmlNodeOrder.Before;
                            }
                        }
                    }
                    break;
                default:
                    cmp -= 2;
                    if (cmp == 0)
                    {
                        while (n1.MoveToNext())
                        {
                            if (n1.IsSamePosition(n2))
                            {
                                return XmlNodeOrder.Before;
                            }
                        }
                    }
                    break;
            }
            return cmp < 0 ? XmlNodeOrder.Before : XmlNodeOrder.After;
        }
Ejemplo n.º 33
0
		public override bool Matches (XPathNavigator node, XsltContext ctx)
		{
			if (! nodeTest.Match (ctx, node))
				return false;
			
			if (nodeTest is NodeTypeTest) {
				// node () is different in xslt patterns
				if (((NodeTypeTest)nodeTest).type == XPathNodeType.All && 
					(node.NodeType == XPathNodeType.Root ||
					node.NodeType == XPathNodeType.Attribute)
				)
				return false;
			}
			
			if (filter == null && patternPrevious == null)
				return true;
			
			XPathNavigator tmpNav;
			if (patternPrevious != null) {
				tmpNav = ((XsltCompiledContext) ctx).GetNavCache (this, node);
				if (!isAncestor) {
					tmpNav.MoveToParent ();
					if (!patternPrevious.Matches (tmpNav, ctx))
						return false;
				} else {
					while (true) {
						if (!tmpNav.MoveToParent ())
							return false;
						
						if (patternPrevious.Matches (tmpNav, ctx))
							break;
					}
				}
			}

						
			if (filter == null)
				return true;

			// Optimization for non-positional predicate
			if (!filter.IsPositional && !(filter.expr is ExprFilter)) {
				return filter.pred.EvaluateBoolean (new NullIterator (node, ctx));
			}

			tmpNav = ((XsltCompiledContext) ctx).GetNavCache (this, node);
			tmpNav.MoveToParent ();

			BaseIterator matches = filter.EvaluateNodeSet (new NullIterator (tmpNav, ctx));
			
			while (matches.MoveNext ()) {
				if (node.IsSamePosition (matches.Current))
					return true;
			}
			
			return false;
		}
        public override bool MoveToNextAttribute()
        {
            switch (_state)
            {
            case State.Content:
                return(MoveToFirstAttribute());

            case State.Attribute:
            {
                if (XPathNodeType.Attribute == _nav.NodeType)
                {
                    return(_nav.MoveToNextAttribute());
                }

                // otherwise it is on a namespace... namespace are in reverse order
                Debug.Assert(XPathNodeType.Namespace == _nav.NodeType);
                XPathNavigator nav = _nav.Clone();
                if (!nav.MoveToParent())
                {
                    return(false);        // shouldn't happen
                }
                if (!nav.MoveToFirstNamespace(XPathNamespaceScope.Local))
                {
                    return(false);        // shouldn't happen
                }
                if (nav.IsSamePosition(_nav))
                {
                    // this was the last one... start walking attributes
                    nav.MoveToParent();
                    if (!nav.MoveToFirstAttribute())
                    {
                        return(false);
                    }
                    // otherwise we are there
                    _nav.MoveTo(nav);
                    return(true);
                }
                else
                {
                    XPathNavigator prev = nav.Clone();
                    for (; ;)
                    {
                        if (!nav.MoveToNextNamespace(XPathNamespaceScope.Local))
                        {
                            Debug.Fail("Couldn't find Namespace Node! Should not happen!");
                            return(false);
                        }
                        if (nav.IsSamePosition(_nav))
                        {
                            _nav.MoveTo(prev);
                            return(true);
                        }
                        prev.MoveTo(nav);
                    }
                    // found previous namespace position
                }
            }

            case State.AttrVal:
                _depth--;
                _state = State.Attribute;
                if (!MoveToNextAttribute())
                {
                    _depth++;
                    _state = State.AttrVal;
                    return(false);
                }
                _nodeType = XmlNodeType.Attribute;
                return(true);

            case State.InReadBinary:
                _state = _savedState;
                if (!MoveToNextAttribute())
                {
                    _state = State.InReadBinary;
                    return(false);
                }
                _readBinaryHelper.Finish();
                return(true);

            default:
                return(false);
            }
        }
Ejemplo n.º 35
0
 private XmlNodeOrder CompareSiblings(XPathNavigator n1, XPathNavigator n2){
     bool attr1 = n1.NodeType == XPathNodeType.Attribute;
     bool attr2 = n2.NodeType == XPathNodeType.Attribute;
     bool ns1 = n1.NodeType == XPathNodeType.Namespace;
     bool ns2 = n2.NodeType == XPathNodeType.Namespace;
     if (! ns1 && ! ns2 && ! attr1 && ! attr2) {
         while (n1.MoveToNext()) {
             if (n1.IsSamePosition(n2))
                 return XmlNodeOrder.Before;
         }
         return XmlNodeOrder.After;
     }
     if (attr1 && attr2) {
         while (n1.MoveToNextAttribute()){
             if (n1.IsSamePosition(n2))
                 return XmlNodeOrder.Before;
         }
         return XmlNodeOrder.After;
     }
     if (attr1){
         return XmlNodeOrder.After;
     }
     if (attr2){
         return XmlNodeOrder.Before;
     }
     if (ns1 && ns2) {
         while (n1.MoveToNextNamespace()) {
             if (n1.IsSamePosition(n2))
                 return XmlNodeOrder.Before;
         }
         return XmlNodeOrder.After;
     }
     if (ns1){
         return XmlNodeOrder.After;
     }
     Debug.Assert(ns2);
     return XmlNodeOrder.Before;
 }
		virtual bool MoveToFollowing (string localName,
			string namespaceURI, XPathNavigator end)
		{
			if (localName == null)
				throw new ArgumentNullException ("localName");
			if (namespaceURI == null)
				throw new ArgumentNullException ("namespaceURI");
			localName = NameTable.Get (localName);
			if (localName == null)
				return false;
			namespaceURI = NameTable.Get (namespaceURI);
			if (namespaceURI == null)
				return false;

			XPathNavigator nav = Clone ();
			switch (nav.NodeType) {
			case XPathNodeType.Attribute:
			case XPathNodeType.Namespace:
				nav.MoveToParent ();
				break;
			}
			do {
				if (!nav.MoveToFirstChild ()) {
					do {
						if (!nav.MoveToNext ()) {
							if (!nav.MoveToParent ())
								return false;
						}
						else
							break;
					} while (true);
				}
				if (end != null && end.IsSamePosition (nav))
					return false;
				if (object.ReferenceEquals (localName, nav.LocalName) &&
					object.ReferenceEquals (namespaceURI, nav.NamespaceURI)) {
					MoveTo (nav);
					return true;
				}
			} while (true);
		}
        public override bool MoveToNextAttribute()
        {
            switch (this.state)
            {
            case State.Content:
                return(this.MoveToFirstAttribute());

            case State.Attribute:
                if (XPathNodeType.Attribute != this.nav.NodeType)
                {
                    XPathNavigator other = this.nav.Clone();
                    if (other.MoveToParent())
                    {
                        if (!other.MoveToFirstNamespace(XPathNamespaceScope.Local))
                        {
                            return(false);
                        }
                        if (other.IsSamePosition(this.nav))
                        {
                            other.MoveToParent();
                            if (!other.MoveToFirstAttribute())
                            {
                                return(false);
                            }
                            this.nav.MoveTo(other);
                            return(true);
                        }
                        XPathNavigator navigator2 = other.Clone();
                        while (other.MoveToNextNamespace(XPathNamespaceScope.Local))
                        {
                            if (other.IsSamePosition(this.nav))
                            {
                                this.nav.MoveTo(navigator2);
                                return(true);
                            }
                            navigator2.MoveTo(other);
                        }
                    }
                    return(false);
                }
                return(this.nav.MoveToNextAttribute());

            case State.AttrVal:
                this.depth--;
                this.state = State.Attribute;
                if (this.MoveToNextAttribute())
                {
                    break;
                }
                this.depth++;
                this.state = State.AttrVal;
                return(false);

            case State.InReadBinary:
                this.state = this.savedState;
                if (this.MoveToNextAttribute())
                {
                    this.readBinaryHelper.Finish();
                    return(true);
                }
                this.state = State.InReadBinary;
                return(false);

            default:
                return(false);
            }
            this.nodeType = XmlNodeType.Attribute;
            return(true);
        }
Ejemplo n.º 38
0
		/// <summary>
		/// Removes the first occurrence of a specific object from the list.
		/// </summary>
		/// <param name="value">The object to remove from the list.</param>
		public void Remove(XPathNavigator nav){
		
			for(int i = 0; i < this.Count; i++){
				if(nav.IsSamePosition((XPathNavigator) this.innerList[i])){
					this.innerList.RemoveAt(i); 
					return; 
				} 
			}
		}
        private XmlNodeOrder CompareSiblings(XPathNavigator n1, XPathNavigator n2)
        {
            int num = 0;
            switch (n1.NodeType)
            {
                case XPathNodeType.Attribute:
                    num++;
                    break;

                case XPathNodeType.Namespace:
                    break;

                default:
                    num += 2;
                    break;
            }
            switch (n2.NodeType)
            {
                case XPathNodeType.Attribute:
                    num--;
                    if (num == 0)
                    {
                        while (n1.MoveToNextAttribute())
                        {
                            if (n1.IsSamePosition(n2))
                            {
                                return XmlNodeOrder.Before;
                            }
                        }
                    }
                    break;

                case XPathNodeType.Namespace:
                    if (num == 0)
                    {
                        while (n1.MoveToNextNamespace())
                        {
                            if (n1.IsSamePosition(n2))
                            {
                                return XmlNodeOrder.Before;
                            }
                        }
                    }
                    break;

                default:
                    num -= 2;
                    if (num == 0)
                    {
                        while (n1.MoveToNext())
                        {
                            if (n1.IsSamePosition(n2))
                            {
                                return XmlNodeOrder.Before;
                            }
                        }
                    }
                    break;
            }
            if (num >= 0)
            {
                return XmlNodeOrder.After;
            }
            return XmlNodeOrder.Before;
        }