Пример #1
0
        /// <summary>
        /// See <see cref="XPathNavigator.IsSamePosition"/>.
        /// </summary>
        public override bool IsSamePosition(XPathNavigator other)
        {
            if (other == null || !(other is SubtreeXPathNavigator))
            {
                return(false);
            }

            SubtreeXPathNavigator nav = (SubtreeXPathNavigator)other;

            return(nav._atroot == this._atroot &&
                   nav._navigator.IsSamePosition(this._navigator) &&
                   nav._root.IsSamePosition(this._root));
        }
Пример #2
0
		public void ShouldNotMoveOutsideRootXmlDocument()
		{
			string xml = @"
	<root>
		<salutations>
			<salute>Hi there <name>kzu</name>.</salute>
			<salute>Bye there <name>vga</name>.</salute>
		</salutations>
		<other>
			Hi there without salutations.
		</other>
	</root>";

			XmlReaderSettings set = new XmlReaderSettings();
			set.IgnoreWhitespace = true;
			XmlDocument doc = new XmlDocument();
			doc.Load(XmlReader.Create(new StringReader(xml), set));
			XPathNavigator nav = doc.CreateNavigator();

			nav.MoveToFirstChild(); //root
			nav.MoveToFirstChild(); //salutations

			SubtreeXPathNavigator subtree = new SubtreeXPathNavigator(nav);
			subtree.MoveToFirstChild(); //salutations
			Assert.AreEqual("salutations", subtree.LocalName);
			subtree.MoveToFirstChild(); //salute
			subtree.MoveToRoot();

			Assert.AreEqual(XPathNodeType.Root, subtree.NodeType);
			subtree.MoveToFirstChild(); //salutations
			Assert.AreEqual("salutations", subtree.LocalName);
		}