当前位置: 首页>>代码示例>>C#>>正文


C# XPathNavigator.MoveToPrevious方法代码示例

本文整理汇总了C#中System.Xml.XPath.XPathNavigator.MoveToPrevious方法的典型用法代码示例。如果您正苦于以下问题:C# XPathNavigator.MoveToPrevious方法的具体用法?C# XPathNavigator.MoveToPrevious怎么用?C# XPathNavigator.MoveToPrevious使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Xml.XPath.XPathNavigator的用法示例。


在下文中一共展示了XPathNavigator.MoveToPrevious方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetXPath

		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");
			
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:29,代码来源:editing.cs

示例2: XmlElementWithAttributes

		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);
		}
开发者ID:Profit0004,项目名称:mono,代码行数:28,代码来源:XPathNavigatorCommonTests.cs

示例3: XmlTwoElementsContent

		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 ());
		}
开发者ID:Profit0004,项目名称:mono,代码行数:24,代码来源:XPathNavigatorCommonTests.cs

示例4: XmlRootElementOnly

		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 ());
		}
开发者ID:Profit0004,项目名称:mono,代码行数:12,代码来源:XPathNavigatorCommonTests.cs

示例5: getXpathPositions

        /// <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);
            }
        }
开发者ID:shu2333,项目名称:dnGrep,代码行数:20,代码来源:GrepEngineBase.cs

示例6: IndexInParent

		int IndexInParent (XPathNavigator nav)
		{
			int n = 0;
			while (nav.MoveToPrevious ())
				n++;
			
			return n;
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:8,代码来源:XslFunctions.cs

示例7: Navigation

		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");
		}
开发者ID:Profit0004,项目名称:mono,代码行数:32,代码来源:XPathNavigatorTests.cs

示例8: MoveToPreviousSibling

 /// <summary>
 /// Reposition the navigator on the previous sibling (no attributes).
 /// </summary>
 public override bool MoveToPreviousSibling(XPathNavigator navigator) {
     return navigator.MoveToPrevious();
 }
开发者ID:uQr,项目名称:referencesource,代码行数:6,代码来源:XmlNavigatorFilter.cs

示例9: XmlSimpleElementContent

		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 ());
		}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:18,代码来源:XPathNavigatorCommonTests.cs

示例10: XmlSimpleTextContent

		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");
		}
开发者ID:nobled,项目名称:mono,代码行数:22,代码来源:ExtensionsTest.cs

示例11: Navigation

		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);
		}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:32,代码来源:XPathNavigatorTests.cs

示例12: path_impl

        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);
             }
//.........这里部分代码省略.........
开发者ID:skurdiukov,项目名称:myxsl,代码行数:101,代码来源:XPathFunctions.cs


注:本文中的System.Xml.XPath.XPathNavigator.MoveToPrevious方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。