Compartir por


XPathNavigator.MoveToFirstAttribute Método

Definición

Cuando se invalida en una clase derivada, mueve al XPathNavigator primer atributo del nodo actual.

public:
 abstract bool MoveToFirstAttribute();
public abstract bool MoveToFirstAttribute();
abstract member MoveToFirstAttribute : unit -> bool
Public MustOverride Function MoveToFirstAttribute () As Boolean

Devoluciones

true es si se XPathNavigator mueve correctamente al primer atributo del nodo actual; en caso contrario, false. Si falsees , la posición de no XPathNavigator cambia.

Ejemplos

En el ejemplo siguiente se usan los MoveToFirstAttribute métodos y MoveToNextAttribute para mostrar todos los atributos de cada libro del books.xml archivo.

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

// Select all book nodes and display all attributes on each book.
XPathNodeIterator nodes = navigator.SelectDescendants("book", "", false);
while (nodes.MoveNext())
{
    XPathNavigator navigator2 = nodes.Current.Clone();
    navigator2.MoveToFirstAttribute();
    Console.WriteLine("{0} = {1}", navigator2.Name, navigator2.Value);

    while (navigator2.MoveToNextAttribute())
    {
        Console.WriteLine("{0} = {1}", navigator2.Name, navigator2.Value);
    }

    Console.WriteLine();
}
Dim document As XPathDocument = New XPathDocument("books.xml")
Dim navigator As XPathNavigator = document.CreateNavigator()

' Select all book nodes and display all attributes on each book.
Dim nodes As XPathNodeIterator = navigator.SelectDescendants("book", "", False)
While nodes.MoveNext()
    Dim navigator2 As XPathNavigator = nodes.Current.Clone()
    navigator2.MoveToFirstAttribute()
    Console.WriteLine("{0} = {1}", navigator2.Name, navigator2.Value)

    While navigator2.MoveToNextAttribute()
        Console.WriteLine("{0} = {1}", navigator2.Name, navigator2.Value)
    End While

    Console.WriteLine()
End While

En el ejemplo se toma el books.xml archivo como entrada.

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

Comentarios

XPathNavigator Si el objeto no está colocado actualmente en un elemento, este método devuelve false y la posición de no XPathNavigator cambia.

Después de una llamada correcta a MoveToFirstAttribute, las LocalNamepropiedades y NamespaceURIPrefix reflejan los valores del atributo . XPathNavigator Cuando se coloca en un atributo , los métodos MoveToNext, MoveToPreviousy MoveToFirst no son aplicables. Estos métodos siempre devuelven false y no cambian la posición de XPathNavigator. En su lugar, puede llamar MoveToNextAttribute a para pasar al siguiente nodo de atributo.

Después de colocar el XPathNavigator control en un atributo, puede llamar MoveToParent a para desplazarse al elemento propietario.

Se aplica a

Consulte también