MoveToFollowing Method (XPathNodeType, XPathNavigator)

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
)

Parameters

type
Type: System.Xml.XPath.XPathNodeType

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

end
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.

  • The MoveToFollowing method does not move to attribute or namespace nodes. If the XPathNodeType parameter value is Attribute or Namespace, the MoveToFollowing method returns false and the position of the XPathNavigator is unchanged.

  • If the XPathNavigator boundary passed as a parameter is not positioned after the position of the current XPathNavigator it is ignored.

  • If XPathNavigator boundary passed as a parameter is null the next following node with the specified XPathNodeType is located in document order.

  • The MoveToFollowing methods cannot be used to move to attribute or namespace nodes. If the XPathNavigator boundary passed as a parameter is positioned over an attribute or namespace node, it is equivalent to the XPathNavigator boundary parameter having been positioned on the first child node of its parent element. This ensures that the parent element of the attribute or namespace node that the XPathNavigator boundary parameter is positioned on can be matched by this method.

  • If the MoveToFollowing method returns false, the position of the XPathNavigator is unchanged.

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();

navigator.MoveToRoot();

while (navigator.MoveToFollowing(XPathNodeType.Text, boundary))
{
    Console.WriteLine(navigator.OuterXml);
}

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>
        <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>

Universal Windows Platform
Available since 10
.NET Framework
Available since 2.0
Silverlight
Available since 4.0
Return to top
Show:
© 2016 Microsoft