XmlNodeReader.MoveToNextAttribute Méthode

Définition

Passe à l’attribut suivant.

public:
 override bool MoveToNextAttribute();
public override bool MoveToNextAttribute();
override this.MoveToNextAttribute : unit -> bool
Public Overrides Function MoveToNextAttribute () As Boolean

Retours

true s’il existe un attribut suivant ; false s’il n’y a plus d’attributs.

Exemples

L’exemple suivant lit un livre.

using System;
using System.IO;
using System.Xml;

public class Sample
{
  public static void Main()
  {
    XmlNodeReader reader = null;

    try
    {
       //Create and load the XML document.
       XmlDocument doc = new XmlDocument();
       doc.LoadXml("<book genre='novel' ISBN='1-861003-78'> " +
                   "<title>Pride And Prejudice</title>" +
                   "<price>19.95</price>" +
                   "</book>");

       //Load the XmlNodeReader
       reader = new XmlNodeReader(doc);

       //Read the attributes on the book element.
       reader.MoveToContent();
       while (reader.MoveToNextAttribute())
       {
         Console.WriteLine("{0} = {1}", reader.Name, reader.Value);
       }

       //Move the reader to the title element.
       reader.Read();

       //Read the title and price elements.
       Console.WriteLine(reader.ReadElementString());
       Console.WriteLine(reader.ReadElementString());
     }

     finally
     {
        if (reader != null)
          reader.Close();
      }
  }
} // End class
Option Explicit
Option Strict

Imports System.IO
Imports System.Xml

Public Class Sample
    
    Public Shared Sub Main()
        Dim reader As XmlNodeReader = Nothing
        
        Try
            'Create and load the XML document.
            Dim doc As New XmlDocument()
            doc.LoadXml("<book genre='novel' ISBN='1-861003-78'> " & _
                       "<title>Pride And Prejudice</title>" & _
                       "<price>19.95</price>" & _
                       "</book>")
            
            'Load the XmlNodeReader 
            reader = New XmlNodeReader(doc)
            
            'Read the attributes on the book element.
            reader.MoveToContent()
            While reader.MoveToNextAttribute()
                Console.WriteLine("{0} = {1}", reader.Name, reader.Value)
            End While
            
            'Move the reader to the title element.
            reader.Read()
            
            'Read the title and price elements.
            Console.WriteLine(reader.ReadElementString())
            Console.WriteLine(reader.ReadElementString())
        
        Finally
            If Not (reader Is Nothing) Then
                reader.Close()
            End If
        End Try
    End Sub
End Class

Remarques

Note

Pour tirer parti des fonctionnalités plus récentes, la pratique recommandée consiste à créer XmlReader des instances à l’aide de la XmlReaderSettings classe et de la Create méthode. Pour plus d’informations, consultez la section Remarques dans la XmlReader page de référence.

Si le nœud actuel n’est pas un nœud d’attribut, cette méthode est équivalente à MoveToFirstAttribute. Si MoveToNextAttribute cette propriété est retournée true, le lecteur passe à l’attribut suivant ; sinon, la position du lecteur ne change pas.

S’applique à