XmlTextReader.AttributeCount 属性

定义

获取当前节点上的属性数目。

public:
 virtual property int AttributeCount { int get(); };
public override int AttributeCount { get; }
member this.AttributeCount : int
Public Overrides ReadOnly Property AttributeCount As Integer

属性值

当前节点上的属性数目。

示例

以下示例显示当前节点上的所有属性。

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.
      }
   }
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.
  }
}
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

注解

注意

从 .NET Framework 2.0 开始,建议使用 XmlReader.Create 方法创建XmlReader实例,以利用新功能。

此属性仅与 ElementDocumentTypeXmlDeclaration 节点相关。 (其他节点类型没有 attributes。)

适用于

另请参阅