AttributeCount Property

XmlTextReader.AttributeCount Property

Gets the number of attributes on the current node.

[Visual Basic]
Overrides Public ReadOnly Property AttributeCount As Integer
public override int AttributeCount {get;}
public: __property int get_AttributeCount();
public override function get AttributeCount() : int;

Property Value

The number of attributes on the current node.


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


[Visual Basic, C#, C++] The following example displays all attributes on the current node.

[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
            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

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

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

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.


Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard

See Also

XmlTextReader Class | XmlTextReader Members | System.Xml Namespace

© 2016 Microsoft