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

XPathNavigator.Clone (Método) ()

 

Cuando se invalida en una clase derivada, se crea un nuevo XPathNavigator que se coloca en el mismo nodo que este XPathNavigator.

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

public abstract XPathNavigator Clone()

Valor devuelto

Type: System.Xml.XPath.XPathNavigator

Nuevo XPathNavigator que se sitúa en el mismo nodo que este XPathNavigator.

The M:System.Xml.XPath.XPathNavigator.Clone method is especially useful in conjunction with the T:System.Xml.XPath.XPathNodeIterator. An T:System.Xml.XPath.XPathNodeIterator is used to iterate over a selected node set, and contains a P:System.Xml.XPath.XPathNodeIterator.Current property which returns an T:System.Xml.XPath.XPathNavigator positioned on the context node of the T:System.Xml.XPath.XPathNodeIterator. However, the T:System.Xml.XPath.XPathNavigator returned by the P:System.Xml.XPath.XPathNodeIterator.Current property cannot be used to move away from the node set. Instead, you clone the returned T:System.Xml.XPath.XPathNavigator and use the cloned navigator to do any additional moves.

The cloned T:System.Xml.XPath.XPathNavigator is not affected by subsequent changes to the original T:System.Xml.XPath.XPathNavigator.

The following example gets all book titles authored by Herman Melville.

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

// Select all books authored by Melville.
XPathNodeIterator nodes = navigator.Select("descendant::book[author/last-name='Melville']");

while (nodes.MoveNext())
{
    // Clone the navigator returned by the Current property. 
    // Use the cloned navigator to get the title element.
    XPathNavigator clone = nodes.Current.Clone();
    clone.MoveToFirstChild();
    Console.WriteLine("Book title: {0}", clone.Value);
}

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

<?xml version="1.0" encoding="utf-8" ?> <bookstore> <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
Disponible desde 10
.NET Framework
Disponible desde 1.1
Silverlight
Disponible desde 4.0
Volver al principio
Mostrar: