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 <" + 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

Комментарии

Note

Рекомендуем создавать XmlReader экземпляры с помощью XmlReader.Create метода, чтобы воспользоваться новыми функциями.

Это свойство относится только к Elementузлам. DocumentTypeXmlDeclaration (Другие типы узлов не имеют атрибутов.)

Применяется к

См. также раздел