本文整理汇总了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");
}
示例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);
}
示例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 ());
}
示例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 ());
}
示例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);
}
}
示例6: IndexInParent
int IndexInParent (XPathNavigator nav)
{
int n = 0;
while (nav.MoveToPrevious ())
n++;
return n;
}
示例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");
}
示例8: MoveToPreviousSibling
/// <summary>
/// Reposition the navigator on the previous sibling (no attributes).
/// </summary>
public override bool MoveToPreviousSibling(XPathNavigator navigator) {
return navigator.MoveToPrevious();
}
示例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 ());
}
示例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");
}
示例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);
}
示例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);
}
//.........这里部分代码省略.........