XPathNavigator.MoveToNextAttribute Méthode
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
En cas de substitution dans une classe dérivée, déplace l’attribut XPathNavigator vers l’attribut suivant.
public:
abstract bool MoveToNextAttribute();
public abstract bool MoveToNextAttribute();
abstract member MoveToNextAttribute : unit -> bool
Public MustOverride Function MoveToNextAttribute () As Boolean
Retours
true si l’attribut XPathNavigator suivant réussit ; false s’il n’y a plus d’attributs. Si false, la position du fichier XPathNavigator n’est pas modifiée.
Exemples
L’exemple suivant utilise les méthodes et MoveToFirstAttribute les MoveToNextAttribute méthodes pour afficher tous les attributs de chaque livre dans le books.xml fichier.
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
L’exemple prend le books.xml fichier en tant qu’entrée.
<?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>
Remarques
Si la XPathNavigator valeur n’est pas actuellement positionnée sur un attribut, cette méthode retourne false et la position de l’attribut XPathNavigator ne change pas.
Lorsque l’attribut XPathNavigator est positionné sur un attribut, les méthodes MoveToNext, MoveToPreviouset MoveToFirst les méthodes ne sont pas applicables. Ces méthodes retournent false toujours et ne modifient pas la position du XPathNavigator.
Une fois l’attribut XPathNavigator positionné, vous pouvez appeler MoveToParent pour accéder à l’élément propriétaire.