MoveToPrevious() public abstract method

public abstract MoveToPrevious ( ) : bool
return bool
Esempio n. 1
0
		public static string GetXPath (XPathNavigator n)
		{
			switch (n.NodeType) {
				case XPathNodeType.Root: return "/";
				case XPathNodeType.Attribute: {
					string ret = "@" + n.Name;
					n.MoveToParent ();
					string s = GetXPath (n);
					return s + (s == "/" ? "" : "/") + ret;
				}

				case XPathNodeType.Element: {
					string ret = n.Name;
					int i = 1;
					while (n.MoveToPrevious ()) {
						if (n.NodeType == XPathNodeType.Element && n.Name == ret)
							i++;
					}
					ret += "[" + i + "]";
					if (n.MoveToParent ()) {
						string s = GetXPath (n);
						return s + (s == "/" ? "" : "/") + ret;
					}
				}
				break;
			}
			throw new Exception ("node type not supported for editing");
			
		}
		private void XmlElementWithAttributes (XPathNavigator nav)
		{
			nav.MoveToFirstChild ();
			AssertNavigator ("#1", nav, XPathNodeType.Element, "", "img", "", "img", "", true, false, true);
			Assert.IsTrue (!nav.MoveToNext ());
			Assert.IsTrue (!nav.MoveToPrevious ());

			Assert.IsTrue (nav.MoveToFirstAttribute ());
			AssertNavigator ("#2", nav, XPathNodeType.Attribute, "", "src", "", "src", "foo.png", false, false, false);
			Assert.IsTrue (!nav.MoveToFirstAttribute ());	// On attributes, it fails.

			Assert.IsTrue (nav.MoveToNextAttribute ());
			AssertNavigator ("#3", nav, XPathNodeType.Attribute, "", "alt", "", "alt", "image Fooooooo!", false, false, false);
			Assert.IsTrue (!nav.MoveToNextAttribute ());

			Assert.IsTrue (nav.MoveToParent ());
			AssertNavigator ("#4", nav, XPathNodeType.Element, "", "img", "", "img", "", true, false, true);

			Assert.IsTrue (nav.MoveToAttribute ("alt", ""));
			AssertNavigator ("#5", nav, XPathNodeType.Attribute, "", "alt", "", "alt", "image Fooooooo!", false, false, false);
			Assert.IsTrue (!nav.MoveToAttribute ("src", ""));	// On attributes, it fails.
			Assert.IsTrue (nav.MoveToParent ());
			Assert.IsTrue (nav.MoveToAttribute ("src", ""));
			AssertNavigator ("#6", nav, XPathNodeType.Attribute, "", "src", "", "src", "foo.png", false, false, false);

			nav.MoveToRoot ();
			AssertNavigator ("#7", nav, XPathNodeType.Root, "", "", "", "", "", false, true, false);
		}
		private void XmlTwoElementsContent (XPathNavigator nav)
		{
			AssertNavigator ("#1", nav, XPathNodeType.Root, "", "", "", "", "", false, true, false);

			Assert.IsTrue (nav.MoveToFirstChild ());
			AssertNavigator ("#2", nav, XPathNodeType.Element, "", "foo", "", "foo", "", false, true, false);
			Assert.IsTrue (!nav.MoveToNext ());
			Assert.IsTrue (!nav.MoveToPrevious ());

			Assert.IsTrue (nav.MoveToFirstChild ());
			AssertNavigator ("#3", nav, XPathNodeType.Element, "", "bar", "", "bar", "", false, false, true);
			Assert.IsTrue (!nav.MoveToFirstChild ());

			Assert.IsTrue (nav.MoveToNext ());
			AssertNavigator ("#4", nav, XPathNodeType.Element, "", "baz", "", "baz", "", false, false, true);
			Assert.IsTrue (!nav.MoveToFirstChild ());

			Assert.IsTrue (nav.MoveToPrevious ());
			AssertNavigator ("#5", nav, XPathNodeType.Element, "", "bar", "", "bar", "", false, false, true);

			nav.MoveToRoot ();
			AssertNavigator ("#6", nav, XPathNodeType.Root, "", "", "", "", "", false, true, false);
			Assert.IsTrue (!nav.MoveToNext ());
		}
		private void XmlRootElementOnly (XPathNavigator nav)
		{
			AssertNavigator ("#1", nav, XPathNodeType.Root, "", "", "", "", "", false, true, false);
			Assert.IsTrue (nav.MoveToFirstChild ());
			AssertNavigator ("#2", nav, XPathNodeType.Element, "", "foo", "", "foo", "", false, false, true);
			Assert.IsTrue (!nav.MoveToFirstChild ());
			Assert.IsTrue (!nav.MoveToNext ());
			Assert.IsTrue (!nav.MoveToPrevious ());
			nav.MoveToRoot ();
			AssertNavigator ("#3", nav, XPathNodeType.Root, "", "", "", "", "", false, true, false);
			Assert.IsTrue (!nav.MoveToNext ());
		}
Esempio n. 5
0
        /// <summary>
        /// Evaluates the absolute position of the current node.
        /// </summary>
        /// <param name="node"></param>
        /// <param name="positions">Lists the number of node in the according level, including root, that is first element. Positions start at 1.</param>
        private void getXpathPositions(XPathNavigator node, ref List<int> positions)
        {
            int pos = 1;

            while (node.MoveToPrevious())
            {
                pos++;
            }

            if (node.MoveToParent())
            {
                positions.Insert(0, pos);
                getXpathPositions(node, ref positions);
            }
        }
		int IndexInParent (XPathNavigator nav)
		{
			int n = 0;
			while (nav.MoveToPrevious ())
				n++;
			
			return n;
		}
Esempio n. 7
0
		public void Navigation ()
		{
			document.LoadXml ("<foo><bar /><baz /></foo>");
			navigator = document.DocumentElement.CreateNavigator ();
			
			Assert.AreEqual ("foo", navigator.Name, "#1");
			Assert.IsTrue (navigator.MoveToFirstChild (), "#2");
			Assert.AreEqual ("bar", navigator.Name, "#3");
			Assert.IsTrue (navigator.MoveToNext (), "#4");
			Assert.AreEqual ("baz", navigator.Name, "#5");
			Assert.IsTrue (!navigator.MoveToNext (), "#6");
			Assert.AreEqual ("baz", navigator.Name, "#7");
			Assert.IsTrue (navigator.MoveToPrevious (), "#8");
			Assert.AreEqual ("bar", navigator.Name, "#9");
			Assert.IsTrue (!navigator.MoveToPrevious (), "#10");
			Assert.IsTrue (navigator.MoveToParent (), "#11");
			Assert.AreEqual ("foo", navigator.Name, "#12");
			navigator.MoveToRoot ();
			Assert.AreEqual (XPathNodeType.Root, navigator.NodeType, "#13");
			Assert.IsTrue (!navigator.MoveToParent (), "#14");
			Assert.AreEqual (XPathNodeType.Root, navigator.NodeType, "#15");
			Assert.IsTrue (navigator.MoveToFirstChild (), "#16");
			Assert.AreEqual ("foo", navigator.Name, "#17");
			Assert.IsTrue (navigator.MoveToFirst (), "#18");
			Assert.AreEqual ("foo", navigator.Name, "#19");
			Assert.IsTrue (navigator.MoveToFirstChild (), "#20");
			Assert.AreEqual ("bar", navigator.Name, "#21");
			Assert.IsTrue (navigator.MoveToNext (), "#22");
			Assert.AreEqual ("baz", navigator.Name, "#23");
			Assert.IsTrue (navigator.MoveToFirst (), "#24");
			Assert.AreEqual ("bar", navigator.Name, "#25");
		}
Esempio n. 8
0
 /// <summary>
 /// Reposition the navigator on the previous sibling (no attributes).
 /// </summary>
 public override bool MoveToPreviousSibling(XPathNavigator navigator) {
     return navigator.MoveToPrevious();
 }
Esempio n. 9
0
 /// <summary>
 /// Reposition the navigator on the previous element sibling with a matching name.
 /// </summary>
 public override bool MoveToPreviousSibling(XPathNavigator navigator) {
     return navigator.MoveToPrevious(this.localName, this.namespaceUri);
 }
		private void XmlSimpleElementContent (XPathNavigator nav)
		{
			AssertNavigator (nav, XPathNodeType.Root, "", "", "", "", "", false, true, false);
			Assert (nav.MoveToFirstChild ());
			AssertNavigator (nav, XPathNodeType.Element, "", "foo", "", "foo", "", false, true, false);
			Assert (!nav.MoveToNext ());
			Assert (!nav.MoveToPrevious ());

			Assert (nav.MoveToFirstChild ());
			AssertNavigator (nav, XPathNodeType.Element, "", "bar", "", "bar", "", false, false, true);

			Assert (nav.MoveToParent ());
			AssertNavigator (nav, XPathNodeType.Element, "", "foo", "", "foo", "", false, true, false);

			nav.MoveToRoot ();
			AssertNavigator (nav, XPathNodeType.Root, "", "", "", "", "", false, true, false);
			Assert (!nav.MoveToNext ());
		}
Esempio n. 11
0
		private void XmlSimpleTextContent (XPathNavigator nav)
		{
			AssertNavigator ("#1", nav, XPathNodeType.Root, "", "", "", "", "Test.", false, true, false);
			Assert.IsTrue (nav.MoveToFirstChild (), "#x1");
			AssertNavigator ("#2", nav, XPathNodeType.Element, "", "foo", "", "foo", "Test.", false, true, false);
			Assert.IsTrue (!nav.MoveToNext (), "#x2");
			Assert.IsTrue (!nav.MoveToPrevious (), "#x3");
			Assert.IsTrue (nav.MoveToFirstChild (), "#x4");
			AssertNavigator ("#3", nav, XPathNodeType.Text, "", "", "", "", "Test.", false, false, false);

			Assert.IsTrue (nav.MoveToParent (), "#x5");
			AssertNavigator ("#4", nav, XPathNodeType.Element, "", "foo", "", "foo", "Test.", false, true, false);

			Assert.IsTrue (nav.MoveToParent (), "#x6");
			AssertNavigator ("#5", nav, XPathNodeType.Root, "", "", "", "", "Test.", false, true, false);

			nav.MoveToFirstChild ();
			nav.MoveToFirstChild ();
			nav.MoveToRoot ();
			AssertNavigator ("#6", nav, XPathNodeType.Root, "", "", "", "", "Test.", false, true, false);
			Assert.IsTrue (!nav.MoveToNext (), "#x7");
		}
		public void Navigation ()
		{
			document.LoadXml ("<foo><bar /><baz /></foo>");
			navigator = document.DocumentElement.CreateNavigator ();
			
			AssertEquals ("foo", navigator.Name);
			Assert (navigator.MoveToFirstChild ());
			AssertEquals ("bar", navigator.Name);
			Assert (navigator.MoveToNext ());
			AssertEquals ("baz", navigator.Name);
			Assert (!navigator.MoveToNext ());
			AssertEquals ("baz", navigator.Name);
			Assert (navigator.MoveToPrevious ());
			AssertEquals ("bar", navigator.Name);
			Assert (!navigator.MoveToPrevious ());
			Assert (navigator.MoveToParent ());
			AssertEquals ("foo", navigator.Name);
			navigator.MoveToRoot ();
			AssertEquals (XPathNodeType.Root, navigator.NodeType);
			Assert (!navigator.MoveToParent ());
			AssertEquals (XPathNodeType.Root, navigator.NodeType);
			Assert (navigator.MoveToFirstChild ());
			AssertEquals ("foo", navigator.Name);
			Assert (navigator.MoveToFirst ());
			AssertEquals ("foo", navigator.Name);
			Assert (navigator.MoveToFirstChild ());
			AssertEquals ("bar", navigator.Name);
			Assert (navigator.MoveToNext ());
			AssertEquals ("baz", navigator.Name);
			Assert (navigator.MoveToFirst ());
			AssertEquals ("bar", navigator.Name);
		}
Esempio n. 13
0
        static void path_impl(XPathNavigator node, List<string> reverseBuffer)
        {
            switch (node.NodeType) {
            case XPathNodeType.Attribute:

               if (node.NamespaceURI.HasValue()) {
                  reverseBuffer.Add(String.Concat("@\"", node.NamespaceURI, "\":", node.LocalName));

               } else {
                  reverseBuffer.Add("@" + node.LocalName);
               }

               break;

            case XPathNodeType.Comment: {

                  int position = 1;

                  while (node.MoveToPrevious()) {
                     if (node.NodeType == XPathNodeType.Comment) {
                        position++;
                     }
                  }

                  reverseBuffer.Add(String.Concat("comment()[", position.ToStringInvariant(), "]"));
               }
               break;

            case XPathNodeType.Element: {

                  string currentLocalName = node.LocalName;
                  string currentNamespace = node.NamespaceURI;
                  int position = 1;

                  while (node.MoveToPrevious()) {
                     if (node.NodeType == XPathNodeType.Element
                        && node.LocalName == currentLocalName
                        && node.NamespaceURI == currentNamespace) {

                        position++;
                     }
                  }

                  reverseBuffer.Add(String.Concat("\"", currentNamespace, "\":", currentLocalName, "[", position.ToStringInvariant(), "]"));
               }
               break;

            case XPathNodeType.Namespace:

               if (node.LocalName.HasValue()) {
                  reverseBuffer.Add("namespace::" + node.Prefix);

               } else {
                  reverseBuffer.Add("namespace::*[\"http://www.w3.org/2005/xpath-functions\":local-name()=\"\"]");
               }

               break;

            case XPathNodeType.ProcessingInstruction: {

                  string currentLocal = node.LocalName;
                  int position = 1;

                  while (node.MoveToPrevious()) {
                     if (node.NodeType == XPathNodeType.ProcessingInstruction
                        && node.LocalName == currentLocal) {

                        position++;
                     }
                  }

                  reverseBuffer.Add(String.Concat("processing-instruction(", currentLocal, ")[", position.ToStringInvariant(), "]"));
               }
               break;

            case XPathNodeType.Root:
               reverseBuffer.Add("/");
               break;

            case XPathNodeType.SignificantWhitespace:
            case XPathNodeType.Text:
            case XPathNodeType.Whitespace: {

                  int position = 1;

                  while (node.MoveToPrevious()) {
                     if (node.NodeType == XPathNodeType.Text) {

                        position++;
                     }
                  }

                  reverseBuffer.Add(String.Concat("text()[", position.ToStringInvariant(), "]"));
               }
               break;
             }

             if (node.MoveToParent()) {
            path_impl(node, reverseBuffer);
             }
        }