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

按文档顺序将 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

元素的 XPathNodeTypeXPathNodeType 不能是 AttributeNamespace

end
XPathNavigator

XPathNavigator 对象,该对象定位在搜索下一个元素时当前 XPathNavigator 不会越过的元素边界上。

返回

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

示例

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

    XPathDocument^ document = gcnew 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);
    }
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

按文档顺序将 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 不会越过的元素边界上。

返回

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

示例

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

XPathDocument^ document = gcnew 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);
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如果边界参数为 null,则指定了本地名称和命名空间 URI 的以下元素将按文档顺序定位。

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

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

适用于

MoveToFollowing(XPathNodeType)

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

元素的 XPathNodeTypeXPathNodeType 不能是 AttributeNamespace

返回

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

示例

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

    XPathDocument^ document = gcnew XPathDocument("contosoBooks.xml");
    XPathNavigator^ navigator = document->CreateNavigator();

navigator->MoveToFollowing(XPathNodeType::Element);

    Console::WriteLine("Position: {0}", navigator->Name);
    Console::WriteLine(navigator->OuterXml);
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

按文档顺序将 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。

返回

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

示例

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

XPathDocument^ document = gcnew 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);
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保持不变。

适用于