XPathNavigator.MoveToNextAttribute Método

Definição

Quando substituído em uma classe derivada, move o XPathNavigator para o atributo seguinte.When overridden in a derived class, moves the XPathNavigator to the next attribute.

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

Retornos

Boolean

true se o XPathNavigator tiver êxito na movimentação para o próximo atributo; false se não houver mais nenhum atributo.true if the XPathNavigator is successful moving to the next attribute; false if there are no more attributes. Se for false, a posição do XPathNavigator permanecerá inalterada.If false, the position of the XPathNavigator is unchanged.

Exemplos

O exemplo a seguir usa MoveToFirstAttribute os MoveToNextAttribute métodos e para exibir todos os atributos de cada livro no books.xml arquivo.The following example uses the MoveToFirstAttribute and MoveToNextAttribute methods to display all the attributes for each book in the books.xml file.

  XPathDocument^ document = gcnew 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();
  }
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

O exemplo usa o arquivo books.xml como entrada.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>  

Comentários

Se o XPathNavigator não estiver posicionado no momento em um atributo, esse método retornará false e a posição do não será XPathNavigator alterada.If the XPathNavigator is not currently positioned on an attribute, this method returns false and the position of the XPathNavigator does not change.

Quando o XPathNavigator está posicionado em um atributo, os métodos MoveToNext , MoveToPrevious e métodos MoveToFirst não são aplicáveis.When the XPathNavigator is positioned on an attribute, the methods MoveToNext, MoveToPrevious, and MoveToFirst methods are not applicable. Esses métodos sempre retornam false e não alteram a posição do XPathNavigator .These methods always return false and do not change the position of the XPathNavigator.

Depois que o XPathNavigator é posicionado em um atributo, você pode chamar MoveToParent para mover para o elemento do proprietário.After the XPathNavigator is positioned on an attribute, you can call MoveToParent to move to the owner element.

Aplica-se a

Confira também