Proprietà XmlTextReader.AttributeCount (System.Xml)

Cambia visualizzazione:
ScriptFree
Riferimento a .NET Framework
Proprietà XmlTextReader.AttributeCount

Ottiene il numero di attributi sul nodo corrente.

Spazio dei nomi: System.Xml
Assembly: System.Xml (in system.xml.dll)

Sintassi

Visual Basic - (Dichiarazione)
Public Overrides ReadOnly Property AttributeCount As Integer
Visual Basic (Utilizzo)
Dim instance As XmlTextReader
Dim value As Integer

value = instance.AttributeCount

C#
public override int AttributeCount { get; }
C++
public:
virtual property int AttributeCount {
	int get () override;
}
J#
/** @property */
public int get_AttributeCount ()

JScript
public override function get AttributeCount () : int

Valore proprietà

Numero di attributi sul nodo corrente.
Note

NotaNota

Nella versione Microsoft .NET Framework versione 2.0 è consigliabile creare istanze di XmlReader utilizzando il metodo System.Xml.XmlReader.Create. In questo modo è possibile sfruttare completamente le nuove funzionalità introdotte in questa versione. Per ulteriori informazioni, vedere Creazione di lettori XML.

Questa proprietà è pertinente soltanto per i nodi Element, DocumentType e XmlDeclaration. Gli altri tipi di nodo non presentano attributi.

Esempio

Nel seguente esempio vengono visualizzati tutti gli attributi sul nodo corrente.

Visual Basic
Public Sub DisplayAttributes(reader As XmlReader)
    If reader.HasAttributes Then
        Console.WriteLine("Attributes of <" & reader.Name & ">")
        Dim i As Integer
        For i = 0 To reader.AttributeCount - 1
            reader.MoveToAttribute(i)
            Console.Write(" {0}={1}", reader.Name, reader.Value)
        Next i
        reader.MoveToElement() 'Moves the reader back to the element node.
    End If
End Sub 'DisplayAttributes

C#
public void DisplayAttributes(XmlReader reader)
{
  if (reader.HasAttributes)
  {
    Console.WriteLine("Attributes of <" + reader.Name + ">");
    for (int i = 0; i < reader.AttributeCount; i++)
    {
      reader.MoveToAttribute(i);
      Console.Write(" {0}={1}", reader.Name, reader.Value);
    }
    reader.MoveToElement(); //Moves the reader back to the element node.
  }
}

C++
public:
   void DisplayAttributes( XmlReader^ reader )
   {
      if ( reader->HasAttributes )
      {
         Console::WriteLine( "Attributes of <{0}>", reader->Name );
         for ( int i = 0; i < reader->AttributeCount; i++ )
         {
            reader->MoveToAttribute( i );
            Console::Write( " {0}={1}", reader->Name, reader->Value );

         }
         reader->MoveToElement(); //Moves the reader back to the element node.
      }
   }

J#
public void DisplayAttributes(XmlReader reader)
{
    if (reader.get_HasAttributes()) {
        Console.WriteLine("Attributes of <" + reader.get_Name() + ">");
        for (int i = 0; i < reader.get_AttributeCount(); i++) {
            reader.MoveToAttribute(i);
            Console.Write(" {0}={1}", reader.get_Name(),
                reader.get_Value());
        }
        reader.MoveToElement();
    } //Moves the reader back to the element node.
} //DisplayAttributes

Piattaforme

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile per Pocket PC, Windows Mobile per Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework non supporta tutte le versioni di ciascuna piattaforma. Per un elenco delle versioni supportate, vedere Requisiti di sistema.

Informazioni sulla versione

.NET Framework

Supportato in: 2.0 1.1 1.0

.NET Compact Framework

Supportato in: 2.0 1.0
Vedere anche