XmlReader.AttributeCount XmlReader.AttributeCount XmlReader.AttributeCount XmlReader.AttributeCount Property


When overridden in a derived class, gets the number of attributes on the current node.

 abstract property int AttributeCount { int get(); };
public abstract int AttributeCount { get; }
member this.AttributeCount : int
Public MustOverride ReadOnly Property AttributeCount As Integer

Property Value

The number of attributes on the current node.


An XmlReader method was called before a previous asynchronous operation finished. In this case, InvalidOperationException is thrown with the message "An asynchronous operation is already in progress."


The following example displays all attributes on the current node.

// Display all attributes.
if (reader.HasAttributes) {
  Console.WriteLine("Attributes of <" + reader.Name + ">");
  for (int i = 0; i < reader.AttributeCount; i++) {
    Console.WriteLine("  {0}", reader[i]);
  // Move the reader back to the element node.
' Display all attributes.
If reader.HasAttributes Then
  Console.WriteLine("Attributes of <" + reader.Name + ">")
  Dim i As Integer
  For i = 0 To (reader.AttributeCount - 1)
    Console.WriteLine("  {0}", reader(i))
  Next i
  ' Move the reader back to the element node.
End If


This property is relevant to Element, DocumentType and XmlDeclaration nodes only. (Other node types do not have attributes.)

Applies to