MoveTo() public abstract method

public abstract MoveTo ( XPathNavigator other ) : bool
other XPathNavigator
return bool
コード例 #1
0
        public override bool MoveNext()
        {
            XPathNavigator n = query.advance();

            if (n != null)
            {
                position++;
                if (!nav.MoveTo(n))
                {
                    nav = n;
                }
                return(true);
            }
            return(false);
        }
コード例 #2
0
 public override bool MoveNextCore()
 {
     while (_right == null || !_right.MoveNext())
     {
         if (!_left.MoveNext())
         {
             return(false);
         }
         _right = _expr.EvaluateNodeSet(_left);
     }
     if (_current == null)
     {
         _current = _right.Current.Clone();
     }
     else if (!_current.MoveTo(_right.Current))
     {
         _current = _right.Current.Clone();
     }
     return(true);
 }
コード例 #3
0
ファイル: XPathNavigator.cs プロジェクト: raj581/Marvin
        static IEnumerable EnumerateChildren(XPathNavigator n, string name, string ns)
        {
            if (!n.MoveToFirstChild())
            {
                yield break;
            }
            n.MoveToParent();
            XPathNavigator nav = n.Clone();

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

            do
            {
                if ((name == String.Empty || nav.LocalName == name) && (ns == String.Empty || nav.NamespaceURI == ns))
                {
                    nav2.MoveTo(nav);
                    yield return(nav2);
                }
            } while (nav.MoveToNext());
        }
コード例 #4
0
        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);
            }
        }
コード例 #5
0
ファイル: XPathNavigator.cs プロジェクト: raj581/Marvin
        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);
        }
コード例 #6
0
        /// <summary>
        /// Position navThis to the same location as navThat.
        /// </summary>
        internal static XPathNavigator SyncToNavigator(XPathNavigator navigatorThis, XPathNavigator navigatorThat) {
            if (navigatorThis == null || !navigatorThis.MoveTo(navigatorThat))
                return navigatorThat.Clone();

            return navigatorThis;
        }
コード例 #7
0
        /// <summary>
        /// Gets the comments for inheritdoc node.
        /// </summary>
        /// <param name="iterator">Iterator for API information</param>
        /// <param name="inheritDocNodeNavigator">Navigator for inheritdoc node</param>
        private void GetComments(XPathNodeIterator iterator, XPathNavigator inheritDocNodeNavigator)
        {
            foreach(XPathNavigator navigator in iterator)
            {
                XPathNavigator contentNodeNavigator = this.commentsIndex[navigator.Value];

                if(contentNodeNavigator == null)
                    continue;

                this.UpdateNode(inheritDocNodeNavigator, contentNodeNavigator);

                if(this.sourceDocument.CreateNavigator().Select(inheritDocExpression).Count == 0)
                    break;

                inheritDocNodeNavigator.MoveTo(this.sourceDocument.CreateNavigator().SelectSingleNode(inheritDocExpression));
            }
        }
コード例 #8
0
        /// <summary>
        /// Updates the node replacing inheritdoc node with comments found.
        /// </summary>
        /// <param name="inheritDocNodeNavigator">Navigator for inheritdoc node</param>
        /// <param name="contentNodeNavigator">Navigator for content</param>
        private void UpdateNode(XPathNavigator inheritDocNodeNavigator, XPathNavigator contentNodeNavigator)
        {
            // retrieve the selection filter if specified.
            string selectValue = inheritDocNodeNavigator.GetAttribute("select", string.Empty);

            if(!string.IsNullOrEmpty(selectValue))
                sourceExpression = XPathExpression.Compile(selectValue);

            inheritDocNodeNavigator.MoveToParent();

            if(inheritDocNodeNavigator.LocalName != "comments" && inheritDocNodeNavigator.LocalName != "element")
                sourceExpression = XPathExpression.Compile(inheritDocNodeNavigator.LocalName);
            else
                inheritDocNodeNavigator.MoveTo(this.sourceDocument.CreateNavigator().SelectSingleNode(inheritDocExpression));

            XPathNodeIterator sources = (XPathNodeIterator)contentNodeNavigator.CreateNavigator().Evaluate(sourceExpression);
            inheritDocNodeNavigator.DeleteSelf();

            // append the source nodes to the target node
            foreach(XPathNavigator source in sources)
                inheritDocNodeNavigator.AppendChild(source);
        }
コード例 #9
0
		private void IsDescendant (XPathNavigator nav)
		{
			XPathNavigator tmp = nav.Clone ();
			XPathNodeIterator iter = nav.Select ("//e");
			iter.MoveNext ();
			Assert.IsTrue (nav.MoveTo (iter.Current), "#1");
			Assert.IsTrue (nav.MoveToFirstAttribute (), "#2");
			Assert.AreEqual ("attr", nav.Name, "#3");
			Assert.AreEqual ("", tmp.Name, "#4");
			Assert.IsTrue (tmp.IsDescendant (nav), "#5");
			Assert.IsTrue (!nav.IsDescendant (tmp), "#6");
			tmp.MoveToFirstChild ();
			Assert.AreEqual ("a", tmp.Name, "#7");
			Assert.IsTrue (tmp.IsDescendant (nav), "#8");
			Assert.IsTrue (!nav.IsDescendant (tmp), "#9");
			tmp.MoveTo (iter.Current);
			Assert.AreEqual ("e", tmp.Name, "#10");
			Assert.IsTrue (tmp.IsDescendant (nav), "#11");
			Assert.IsTrue (!nav.IsDescendant (tmp), "#12");
		}
コード例 #10
0
		private void MoveToNamespaces (XPathNavigator nav)
		{
			XPathNodeIterator iter = nav.Select ("//e");
			iter.MoveNext ();
			nav.MoveTo (iter.Current);
			Assert.AreEqual ("e", nav.Name, "#1");
			nav.MoveToFirstNamespace ();
			Assert.AreEqual ("x", nav.Name, "#2");
			nav.MoveToNextNamespace ();
			Assert.AreEqual ("xml", nav.Name, "#3");
		}
コード例 #11
0
        /// <summary>
        /// Gets the comments for inheritdoc node.
        /// </summary>
        /// <param name="iterator">Iterator for API information</param>
        /// <param name="inheritDocNodeNavigator">Navigator for inheritdoc node</param>
        public void GetComments(XPathNodeIterator iterator, XPathNavigator inheritDocNodeNavigator)
        {
            foreach (XPathNavigator navigator in iterator)
            {
                XPathNavigator contentNodeNavigator = this.index.GetContent(navigator.Value);

                if (contentNodeNavigator == null)
                {
                    continue;
                }

                this.UpdateNode(inheritDocNodeNavigator, contentNodeNavigator);

                if (this.sourceDocument.CreateNavigator().Select(inheritDocExpression).Count == 0)
                {
                    break;
                }
                else
                {
                    inheritDocNodeNavigator.MoveTo(this.sourceDocument.CreateNavigator().SelectSingleNode(inheritDocExpression));
                }
            }
        }
コード例 #12
0
		private void IsDescendant (XPathNavigator nav)
		{
			XPathNavigator tmp = nav.Clone ();
			XPathNodeIterator iter = nav.Select ("//e");
			iter.MoveNext ();
			Assert (nav.MoveTo (iter.Current));
			Assert (nav.MoveToFirstAttribute ());
			AssertEquals ("attr", nav.Name);
			AssertEquals ("", tmp.Name);
			Assert (tmp.IsDescendant (nav));
			Assert (!nav.IsDescendant (tmp));
			tmp.MoveToFirstChild ();
			AssertEquals ("a", tmp.Name);
			Assert (tmp.IsDescendant (nav));
			Assert (!nav.IsDescendant (tmp));
			tmp.MoveTo (iter.Current);
			AssertEquals ("e", tmp.Name);
			Assert (tmp.IsDescendant (nav));
			Assert (!nav.IsDescendant (tmp));
		}
コード例 #13
0
        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);
        }
コード例 #14
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);
        }