XPathNodeIterator.Current Propiedad
Definición
Importante
Parte de la información hace referencia a la versión preliminar del producto, que puede haberse modificado sustancialmente antes de lanzar la versión definitiva. Microsoft no otorga ninguna garantía, explícita o implícita, con respecto a la información proporcionada aquí.
Cuando se reemplaza en una clase derivada, obtiene el XPathNavigator objeto para este XPathNodeIterator, situado en el nodo de contexto actual.
public:
abstract property System::Xml::XPath::XPathNavigator ^ Current { System::Xml::XPath::XPathNavigator ^ get(); };
public abstract System.Xml.XPath.XPathNavigator? Current { get; }
public abstract System.Xml.XPath.XPathNavigator Current { get; }
member this.Current : System.Xml.XPath.XPathNavigator
Public MustOverride ReadOnly Property Current As XPathNavigator
Valor de propiedad
Objeto XPathNavigator situado en el nodo de contexto desde el que se seleccionó el conjunto de nodos. Se MoveNext() debe llamar al método para mover al XPathNodeIterator primer nodo del conjunto seleccionado.
Ejemplos
En el ejemplo siguiente se obtienen todos los títulos de libro creados por Herman Melville mediante la Current propiedad del XPathNodeIterator objeto y el Clone método de la XPathNavigator clase .
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);
}
Dim document As XPathDocument = New XPathDocument("books.xml")
Dim navigator As XPathNavigator = document.CreateNavigator()
' Select all books authored by Melville.
Dim nodes As XPathNodeIterator = 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.
Dim clone As XPathNavigator = nodes.Current.Clone()
clone.MoveToFirstChild()
Console.WriteLine("Book title: {0}", clone.Value)
End While
En el ejemplo se toma el archivo contosoBooks.xml como entrada.
<?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>
Comentarios
Puede usar las propiedades del objeto devuelto XPathNavigator para obtener información sobre el nodo actual. Sin embargo, el objeto devuelto XPathNavigator no debe modificarse. El objeto devuelto XPathNavigator no se puede mover del conjunto de nodos seleccionado.
Como alternativa, puede clonar el XPathNavigator objeto mediante el Clone método de la XPathNavigator clase . A continuación, el objeto clonado XPathNavigator se puede quitar del conjunto de nodos seleccionado. Este método de clonación del XPathNavigator objeto puede afectar al rendimiento de la consulta XPath.
Si los SelectAncestorsmétodos , SelectDescendantsy SelectChildren no generan nodos seleccionados, es posible que la Current propiedad no apunte al nodo de contexto.
Para probar si se han seleccionado nodos, use la Count propiedad tal como se muestra en el ejemplo siguiente.