Este artículo se tradujo automáticamente. Para ver el artículo en inglés, active la casilla Inglés. Además, puede mostrar el texto en inglés en una ventana emergente si mueve el puntero del mouse sobre el texto.
Traducción
Inglés

Método XPathNavigator.MoveToFollowing (String, String, XPathNavigator)

 

Publicado: octubre de 2016

Mueve XPathNavigator al elemento con el nombre local y el identificador URI de espacio de nombres especificados al límite especificado, en el orden del documento.

Espacio de nombres:   System.Xml.XPath
Ensamblado:  System.Xml (en System.Xml.dll)

public virtual bool MoveToFollowing(
	string localName,
	string namespaceURI,
	XPathNavigator end
)

Parámetros

localName
Type: System.String

Nombre local del elemento.

namespaceURI
Type: System.String

Identificador URI de espacio de nombres del elemento.

end
Type: System.Xml.XPath.XPathNavigator

Objeto XPathNavigator situado en el límite del elemento que el XPathNavigator actual no sobrepasa durante la búsqueda del elemento siguiente.

Valor devuelto

Type: System.Boolean

true si XPathNavigator se mueve correctamente; en caso contrario, false.

  • If the T:System.Xml.XPath.XPathNavigator boundary passed as a parameter is not positioned after the position of the current T:System.Xml.XPath.XPathNavigator it is ignored.

  • If the T:System.Xml.XPath.XPathNavigator boundary parameter is null, the following element with the local name and namespace URI specified is located in document order.

  • The Overload:System.Xml.XPath.XPathNavigator.MoveToFollowing methods cannot be used to move to attribute or namespace nodes. If the T:System.Xml.XPath.XPathNavigator boundary passed as a parameter is positioned over an attribute or namespace node, it is equivalent to the T:System.Xml.XPath.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 T:System.Xml.XPath.XPathNavigator boundary parameter is positioned on can be matched by this method.

  • If the M:System.Xml.XPath.XPathNavigator.MoveToFollowing(System.String,System.String,System.Xml.XPath.XPathNavigator) method returns false, the position of the T:System.Xml.XPath.XPathNavigator is unchanged.

In the following example, the T:System.Xml.XPath.XPathNavigator is moved from the root of the contosoBooks.xml file to the following book element. A clone of the T:System.Xml.XPath.XPathNavigator object is made using the M:System.Xml.XPath.XPathNavigator.Clone method and is moved from the book element to the following first-name element. The cloned T:System.Xml.XPath.XPathNavigator, positioned on the first-name element, will be used as a boundary. Changes in the position of the cloned T:System.Xml.XPath.XPathNavigator do not affect the original T:System.Xml.XPath.XPathNavigator. The original T:System.Xml.XPath.XPathNavigator then attempts to move to the following price element using the M:System.Xml.XPath.XPathNavigator.MoveToFollowing(System.String,System.String,System.Xml.XPath.XPathNavigator) method with the boundary passed as a parameter. This move fails because the following price element is beyond the boundary. The original T:System.Xml.XPath.XPathNavigator then attempts to move to the following title element which is before the boundary using the same method and succeeds.

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

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>

.NET Framework
Disponible desde 2.0
Silverlight
Disponible desde 4.0
Volver al principio
Mostrar: