XmlNodeReader.MoveToAttribute Metodo

Definizione

Passa all'attributo specificato.

Overload

MoveToAttribute(Int32)

Passa all'attributo con l'indice specificato.

MoveToAttribute(String)

Passa all'attributo con il nome specificato.

MoveToAttribute(String, String)

Passa all'attributo con il nome locale e l'URI dello spazio dei nomi specificati.

MoveToAttribute(Int32)

Source:
XmlNodeReader.cs
Source:
XmlNodeReader.cs
Source:
XmlNodeReader.cs

Passa all'attributo con l'indice specificato.

public:
 override void MoveToAttribute(int attributeIndex);
public override void MoveToAttribute (int attributeIndex);
override this.MoveToAttribute : int -> unit
Public Overrides Sub MoveToAttribute (attributeIndex As Integer)

Parametri

attributeIndex
Int32

Indice dell'attributo.

Eccezioni

Il valore del parametro i è minore di zero oppure è maggiore o uguale a AttributeCount.

Esempio

Nell'esempio seguente vengono letti tutti gli attributi nel nodo radice.

#using <System.Xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{
   XmlNodeReader^ reader = nullptr;
   try
   {
      
      //Create and load the XML document.
      XmlDocument^ doc = gcnew XmlDocument;
      doc->LoadXml( "<book genre='novel' ISBN='1-861003-78' publicationdate='1987'> "
      "</book>" );
      
      //Load the XmlNodeReader 
      reader = gcnew XmlNodeReader( doc );
      
      //Read the attributes on the root element.
      reader->MoveToContent();
      if ( reader->HasAttributes )
      {
         for ( int i = 0; i < reader->AttributeCount; i++ )
         {
            reader->MoveToAttribute( i );
            Console::WriteLine( "{0} = {1}", reader->Name, reader->Value );

         }
         reader->MoveToElement();
      }
   }
   finally
   {
      if ( reader != nullptr )
            reader->Close();
   }

}
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' publicationdate='1987'> " +
                   "</book>");

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

       //Read the attributes on the root element.
       reader.MoveToContent();
       if (reader.HasAttributes){
         for (int i=0; i<reader.AttributeCount; i++){
            reader.MoveToAttribute(i);
            Console.WriteLine("{0} = {1}", reader.Name, reader.Value);
         }
         //Return the reader to the book element.
         reader.MoveToElement();
       }
     }

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

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' publicationdate='1987'> " & _
                       "</book>")
            
            'Load the XmlNodeReader 
            reader = New XmlNodeReader(doc)
            
            'Read the attributes on the root element.
            reader.MoveToContent()
            If reader.HasAttributes Then
                Dim i As Integer
                For i = 0 To reader.AttributeCount - 1
                    reader.MoveToAttribute(i)
                    Console.WriteLine("{0} = {1}", reader.Name, reader.Value)
                Next i
                'Return the reader to the book element.
                reader.MoveToElement()
            End If
        
        Finally
            If Not (reader Is Nothing) Then
                reader.Close()
            End If
        End Try
    End Sub
End Class

Commenti

Nota

In .NET Framework 2.0, la procedura consigliata consiste nel creare XmlReader istanze usando la XmlReaderSettings classe e il Create metodo . In questo modo è possibile sfruttare appieno tutte le nuove funzionalità introdotte in .NET Framework. Per altre informazioni, vedere la sezione Osservazioni nella pagina di XmlReader riferimento.

Si applica a

MoveToAttribute(String)

Source:
XmlNodeReader.cs
Source:
XmlNodeReader.cs
Source:
XmlNodeReader.cs

Passa all'attributo con il nome specificato.

public:
 override bool MoveToAttribute(System::String ^ name);
public override bool MoveToAttribute (string name);
override this.MoveToAttribute : string -> bool
Public Overrides Function MoveToAttribute (name As String) As Boolean

Parametri

name
String

Nome completo dell'attributo.

Restituisce

true se l'attributo viene trovato; in caso contrario, false. Se viene restituito il valore false, la posizione del lettore non subirà alcuna modifica.

Commenti

Nota

In .NET Framework 2.0, la procedura consigliata consiste nel creare XmlReader istanze usando la XmlReaderSettings classe e il Create metodo . In questo modo è possibile sfruttare appieno tutte le nuove funzionalità introdotte in .NET Framework. Per altre informazioni, vedere la sezione Osservazioni nella pagina di XmlReader riferimento.

Dopo aver chiamato questo metodo, le Nameproprietà , NamespaceURIe Prefix riflettono le proprietà di tale attributo.

Si applica a

MoveToAttribute(String, String)

Source:
XmlNodeReader.cs
Source:
XmlNodeReader.cs
Source:
XmlNodeReader.cs

Passa all'attributo con il nome locale e l'URI dello spazio dei nomi specificati.

public:
 override bool MoveToAttribute(System::String ^ name, System::String ^ namespaceURI);
public override bool MoveToAttribute (string name, string? namespaceURI);
public override bool MoveToAttribute (string name, string namespaceURI);
override this.MoveToAttribute : string * string -> bool
Public Overrides Function MoveToAttribute (name As String, namespaceURI As String) As Boolean

Parametri

name
String

Nome locale dell'attributo.

namespaceURI
String

URI dello spazio dei nomi dell'attributo.

Restituisce

true se l'attributo viene trovato; in caso contrario, false. Se viene restituito il valore false, la posizione del lettore non subirà alcuna modifica.

Commenti

Nota

In .NET Framework 2.0, la procedura consigliata consiste nel creare XmlReader istanze usando la XmlReaderSettings classe e il Create metodo . In questo modo è possibile sfruttare appieno tutte le nuove funzionalità introdotte in .NET Framework. Per altre informazioni, vedere la sezione Osservazioni nella pagina di XmlReader riferimento.

Dopo aver chiamato questo metodo, le Nameproprietà , NamespaceURIe Prefix riflettono le proprietà di tale attributo.

Si applica a