语言

XPathNavigator.MoveToFollowing 方法

定义

将 XPathNavigator 移动到文档顺序中的指定元素。

重载

名称 说明
MoveToFollowing(XPathNodeType, XPathNavigator)

按 XPathNavigator 文档顺序将指定的以下元素 XPathNodeType 移动到指定的边界。

MoveToFollowing(String, String, XPathNavigator)

将 XPathNavigator 具有指定本地名称和命名空间 URI 的元素移动到文档顺序中指定的边界。

MoveToFollowing(XPathNodeType)

按 XPathNavigator 文档顺序移动指定的以下元素 XPathNodeType 。

MoveToFollowing(String, String)

XPathNavigator移动具有文档顺序中指定的本地名称和命名空间 URI 的元素。

MoveToFollowing(XPathNodeType, XPathNavigator)

Source:
XPathNavigator.cs
Source:
XPathNavigator.cs
Source:
XPathNavigator.cs
Source:
XPathNavigator.cs
Source:
XPathNavigator.cs

按 XPathNavigator 文档顺序将指定的以下元素 XPathNodeType 移动到指定的边界。

public:
 virtual bool MoveToFollowing(System::Xml::XPath::XPathNodeType type, System::Xml::XPath::XPathNavigator ^ end);
public virtual bool MoveToFollowing(System.Xml.XPath.XPathNodeType type, System.Xml.XPath.XPathNavigator? end);
public virtual bool MoveToFollowing(System.Xml.XPath.XPathNodeType type, System.Xml.XPath.XPathNavigator end);
abstract member MoveToFollowing : System.Xml.XPath.XPathNodeType * System.Xml.XPath.XPathNavigator -> bool
override this.MoveToFollowing : System.Xml.XPath.XPathNodeType * System.Xml.XPath.XPathNavigator -> bool
Public Overridable Function MoveToFollowing (type As XPathNodeType, end As XPathNavigator) As Boolean

参数

type
XPathNodeType

元素 XPathNodeType 的元素。 不能XPathNodeTypeAttribute或 Namespace。

end
XPathNavigator

XPathNavigator定位在元素边界上的对象,当前XPathNavigator在搜索以下元素时不会移动。

返回

true 如果成功移动, XPathNavigator 则为 :否则为 false。

示例

在以下示例中,将 XPathNavigator 文件根 contosoBooks.xml 目录移动到以下 price 元素。 使用XPathNavigator该方法克隆Clone对象。 克隆 XPathNavigator的,定位在 price 元素上,将用作边界。 克隆 XPathNavigator 位置的更改不会影响原始 XPathNavigator内容。 原始XPathNavigator文件使用contosoBooks.xml该方法移回文件的根MoveToRoot目录。 使用方法和 <a0/> 检索作者的标题和名字和姓氏。 此方法 MoveToFollowing 将返回 true, price 直到达到元素边界。

XPathDocument document = new XPathDocument("contosoBooks.xml");
XPathNavigator navigator = document.CreateNavigator();

navigator.MoveToFollowing("price", "http://www.contoso.com/books");
XPathNavigator boundary = navigator.Clone();

navigator.MoveToRoot();

while (navigator.MoveToFollowing(XPathNodeType.Text, boundary))
{
    Console.WriteLine(navigator.OuterXml);
}
Dim document As XPathDocument = New XPathDocument("contosoBooks.xml")
Dim navigator As XPathNavigator = document.CreateNavigator()

navigator.MoveToFollowing("price", "http://www.contoso.com/books")
Dim boundary As XPathNavigator = navigator.Clone()

navigator.MoveToRoot()

While navigator.MoveToFollowing(XPathNodeType.Text, boundary)
    Console.WriteLine(navigator.OuterXml)
End While

该示例将 contosoBooks.xml 文件作为输入。

<?xml version="1.0" encoding="utf-8" ?>
<bookstore xmlns="http://www.contoso.com/books">
    <book genre="autobiography" publicationdate="1981-03-22" ISBN="1-861003-11-0">
        <title>The Autobiography of Benjamin Franklin</title>
        <author>
            <first-name>Benjamin</first-name>
            <last-name>Franklin</last-name>
        </author>
        <price>8.99</price>
    </book>
    <book genre="novel" publicationdate="1967-11-17" ISBN="0-201-63361-2">
        <title>The Confidence Man</title>
        <author>
            <first-name>Herman</first-name>
            <last-name>Melville</last-name>
        </author>
        <price>11.99</price>
    </book>
    <book genre="philosophy" publicationdate="1991-02-15" ISBN="1-861001-57-6">
        <title>The Gorgias</title>
        <author>
            <name>Plato</name>
        </author>
        <price>9.99</price>
    </book>
</bookstore>

注解

适用于

MoveToFollowing(String, String, XPathNavigator)

Source:
XPathNavigator.cs
Source:
XPathNavigator.cs
Source:
XPathNavigator.cs
Source:
XPathNavigator.cs
Source:
XPathNavigator.cs

将 XPathNavigator 具有指定本地名称和命名空间 URI 的元素移动到文档顺序中指定的边界。

public:
 virtual bool MoveToFollowing(System::String ^ localName, System::String ^ namespaceURI, System::Xml::XPath::XPathNavigator ^ end);
public virtual bool MoveToFollowing(string localName, string namespaceURI, System.Xml.XPath.XPathNavigator? end);
public virtual bool MoveToFollowing(string localName, string namespaceURI, System.Xml.XPath.XPathNavigator end);
abstract member MoveToFollowing : string * string * System.Xml.XPath.XPathNavigator -> bool
override this.MoveToFollowing : string * string * System.Xml.XPath.XPathNavigator -> bool
Public Overridable Function MoveToFollowing (localName As String, namespaceURI As String, end As XPathNavigator) As Boolean

参数

localName
String

元素的本地名称。

namespaceURI
String

元素的命名空间 URI。

end
XPathNavigator

XPathNavigator定位在元素边界上的对象,当前XPathNavigator在搜索以下元素时不会移动。

返回

true 如果成功移动, XPathNavigator 则为 :否则为 false。

示例

在以下示例中,将 XPathNavigator 文件根 contosoBooks.xml 目录移动到以下 book 元素。 对象的克隆 XPathNavigator 是使用 Clone 该方法进行的,并且从 book 元素移动到以下 first-name 元素。 克隆 XPathNavigator的,定位在 first-name 元素上,将用作边界。 克隆 XPathNavigator 位置的更改不会影响原始 XPathNavigator内容。 然后,原始XPathNavigator文件尝试使用price作为参数传递的边界的方法移动到以下MoveToFollowing元素。 此移动失败,因为以下 price 元素超出边界。 然后,原始 XPathNavigator 元素尝试移动到以下 title 元素,该元素之前使用相同方法和成功。

XPathDocument document = new XPathDocument("contosoBooks.xml");
XPathNavigator navigator = document.CreateNavigator();

navigator.MoveToFollowing("book", "http://www.contoso.com/books");
XPathNavigator boundary = navigator.Clone();
boundary.MoveToFollowing("first-name", "http://www.contoso.com/books");

navigator.MoveToFollowing("price", "http://www.contoso.com/books", boundary);

Console.WriteLine("Position (after boundary): {0}", navigator.Name);
Console.WriteLine(navigator.OuterXml);

navigator.MoveToFollowing("title", "http://www.contoso.com/books", boundary);

Console.WriteLine("Position (before boundary): {0}", navigator.Name);
Console.WriteLine(navigator.OuterXml);
Dim document As XPathDocument = New XPathDocument("contosoBooks.xml")
Dim navigator As XPathNavigator = document.CreateNavigator()

navigator.MoveToFollowing("book", "http://www.contoso.com/books")
Dim boundary As XPathNavigator = navigator.Clone()
boundary.MoveToFollowing("first-name", "http://www.contoso.com/books")

navigator.MoveToFollowing("price", "http://www.contoso.com/books", boundary)

Console.WriteLine("Position (after boundary): {0}", navigator.Name)
Console.WriteLine(navigator.OuterXml)

navigator.MoveToFollowing("title", "http://www.contoso.com/books", boundary)

Console.WriteLine("Position (before boundary): {0}", navigator.Name)
Console.WriteLine(navigator.OuterXml)

该示例将 contosoBooks.xml 文件作为输入。

<?xml version="1.0" encoding="utf-8" ?>
<bookstore xmlns="http://www.contoso.com/books">
    <book genre="autobiography" publicationdate="1981-03-22" ISBN="1-861003-11-0">
        <title>The Autobiography of Benjamin Franklin</title>
        <author>
            <first-name>Benjamin</first-name>
            <last-name>Franklin</last-name>
        </author>
        <price>8.99</price>
    </book>
    <book genre="novel" publicationdate="1967-11-17" ISBN="0-201-63361-2">
        <title>The Confidence Man</title>
        <author>
            <first-name>Herman</first-name>
            <last-name>Melville</last-name>
        </author>
        <price>11.99</price>
    </book>
    <book genre="philosophy" publicationdate="1991-02-15" ISBN="1-861001-57-6">
        <title>The Gorgias</title>
        <author>
            <name>Plato</name>
        </author>
        <price>9.99</price>
    </book>
</bookstore>

注解

  • XPathNavigator如果作为参数传递的边界在当前XPathNavigator位置之后未定位,则忽略该边界。

  • 如果边界参数为XPathNavigator,则指定本地名称和命名空间 URI 的null以下元素按文档顺序排列。

  • 方法 MoveToFollowing 不能用于移动到属性或命名空间节点。 如果将作为参数传递的 XPathNavigator 边界定位在属性或命名空间节点上,则它等效于 XPathNavigator 已定位在其父元素的第一个子节点上的边界参数。 这可确保边界参数定位到的属性或命名空间节点 XPathNavigator 的父元素可由此方法匹配。

  • MoveToFollowing如果方法返回false,则位置XPathNavigator不变。

适用于

MoveToFollowing(XPathNodeType)

Source:
XPathNavigator.cs
Source:
XPathNavigator.cs
Source:
XPathNavigator.cs
Source:
XPathNavigator.cs
Source:
XPathNavigator.cs

按 XPathNavigator 文档顺序移动指定的以下元素 XPathNodeType 。

public:
 virtual bool MoveToFollowing(System::Xml::XPath::XPathNodeType type);
public virtual bool MoveToFollowing(System.Xml.XPath.XPathNodeType type);
abstract member MoveToFollowing : System.Xml.XPath.XPathNodeType -> bool
override this.MoveToFollowing : System.Xml.XPath.XPathNodeType -> bool
Public Overridable Function MoveToFollowing (type As XPathNodeType) As Boolean

参数

type
XPathNodeType

元素 XPathNodeType 的元素。 不能XPathNodeTypeAttribute或 Namespace。

返回

true 如果成功移动, XPathNavigator 则为 :否则为 false。

示例

在以下示例中,将 XPathNavigator 文件根 contosoBooks.xml 目录移动到以下 bookstore 元素。

XPathDocument document = new XPathDocument("contosoBooks.xml");
XPathNavigator navigator = document.CreateNavigator();

navigator.MoveToFollowing(XPathNodeType.Element);

Console.WriteLine("Position: {0}", navigator.Name);
Console.WriteLine(navigator.OuterXml);
Dim document As XPathDocument = New XPathDocument("contosoBooks.xml")
Dim navigator As XPathNavigator = document.CreateNavigator()

navigator.MoveToFollowing(XPathNodeType.Element)

Console.WriteLine("Position: {0}", navigator.Name)
Console.WriteLine(navigator.OuterXml)

该示例将 contosoBooks.xml 文件作为输入。

<?xml version="1.0" encoding="utf-8" ?>
<bookstore xmlns="http://www.contoso.com/books">
    <book genre="autobiography" publicationdate="1981-03-22" ISBN="1-861003-11-0">
        <title>The Autobiography of Benjamin Franklin</title>
        <author>
            <first-name>Benjamin</first-name>
            <last-name>Franklin</last-name>
        </author>
        <price>8.99</price>
    </book>
    <book genre="novel" publicationdate="1967-11-17" ISBN="0-201-63361-2">
        <title>The Confidence Man</title>
        <author>
            <first-name>Herman</first-name>
            <last-name>Melville</last-name>
        </author>
        <price>11.99</price>
    </book>
    <book genre="philosophy" publicationdate="1991-02-15" ISBN="1-861001-57-6">
        <title>The Gorgias</title>
        <author>
            <name>Plato</name>
        </author>
        <price>9.99</price>
    </book>
</bookstore>

注解

适用于

MoveToFollowing(String, String)

Source:
XPathNavigator.cs
Source:
XPathNavigator.cs
Source:
XPathNavigator.cs
Source:
XPathNavigator.cs
Source:
XPathNavigator.cs

XPathNavigator移动具有文档顺序中指定的本地名称和命名空间 URI 的元素。

public:
 virtual bool MoveToFollowing(System::String ^ localName, System::String ^ namespaceURI);
public virtual bool MoveToFollowing(string localName, string namespaceURI);
abstract member MoveToFollowing : string * string -> bool
override this.MoveToFollowing : string * string -> bool
Public Overridable Function MoveToFollowing (localName As String, namespaceURI As String) As Boolean

参数

localName
String

元素的本地名称。

namespaceURI
String

元素的命名空间 URI。

返回

true 如果成功移动, XPathNavigator 则为 :否则为 false。

示例

在以下示例中,将 XPathNavigator 文件根 contosoBooks.xml 目录移动到第一个 price 元素。

XPathDocument document = new XPathDocument("contosoBooks.xml");
XPathNavigator navigator = document.CreateNavigator();

navigator.MoveToFollowing("price", "http://www.contoso.com/books");

Console.WriteLine("Position: {0}", navigator.Name);
Console.WriteLine(navigator.OuterXml);
Dim document As XPathDocument = New XPathDocument("contosoBooks.xml")
Dim navigator As XPathNavigator = document.CreateNavigator()

navigator.MoveToFollowing("price", "http://www.contoso.com/books")

Console.WriteLine("Position: {0}", navigator.Name)
Console.WriteLine(navigator.OuterXml)

该示例将 contosoBooks.xml 文件作为输入。

<?xml version="1.0" encoding="utf-8" ?>
<bookstore xmlns="http://www.contoso.com/books">
    <book genre="autobiography" publicationdate="1981-03-22" ISBN="1-861003-11-0">
        <title>The Autobiography of Benjamin Franklin</title>
        <author>
            <first-name>Benjamin</first-name>
            <last-name>Franklin</last-name>
        </author>
        <price>8.99</price>
    </book>
    <book genre="novel" publicationdate="1967-11-17" ISBN="0-201-63361-2">
        <title>The Confidence Man</title>
        <author>
            <first-name>Herman</first-name>
            <last-name>Melville</last-name>
        </author>
        <price>11.99</price>
    </book>
    <book genre="philosophy" publicationdate="1991-02-15" ISBN="1-861001-57-6">
        <title>The Gorgias</title>
        <author>
            <name>Plato</name>
        </author>
        <price>9.99</price>
    </book>
</bookstore>

注解

MoveToFollowing如果方法返回false,则位置XPathNavigator不变。

适用于