XPathNavigator.MoveToFollowing Method (XPathNodeType, XPathNavigator)

Moves the XPathNavigator to the following element of the XPathNodeType specified, to the boundary specified, in document order.

Namespace:  System.Xml.XPath
Assembly:  System.Xml (in System.Xml.dll)

public virtual bool MoveToFollowing(
	XPathNodeType type,
	XPathNavigator end


Type: System.Xml.XPath.XPathNodeType

The XPathNodeType of the element. The XPathNodeType cannot be Attribute or Namespace.

Type: System.Xml.XPath.XPathNavigator

The XPathNavigator object positioned on the element boundary which the current XPathNavigator will not move past while searching for the following element.

Return Value

Type: System.Boolean
true if the XPathNavigator moved successfully; otherwise false.

In the following example, the XPathNavigator is moved from the root of the contosoBooks.xml file to the following price element. A clone of the XPathNavigator object is made using the Clone method. The cloned XPathNavigator, positioned on the price element, will be used as a boundary. Changes in the position of the cloned XPathNavigator do not affect the original XPathNavigator. The original XPathNavigator is moved back to the root of the contosoBooks.xml file using the MoveToRoot method. The title and first and last name of the author are retrieved using the MoveToFollowing method and an XPathNodeType of Text. The MoveToFollowing method will return true until the price element boundary is reached.

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

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


while (navigator.MoveToFollowing(XPathNodeType.Text, boundary))

The example takes the contosoBooks.xml file as an input.

<?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>
    <book genre="novel" publicationdate="1967-11-17" ISBN="0-201-63361-2">
        <title>The Confidence Man</title>
    <book genre="philosophy" publicationdate="1991-02-15" ISBN="1-861001-57-6">
        <title>The Gorgias</title>

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
© 2014 Microsoft