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

定义

当在派生类中被重写时,获取当前节点上的属性数。When overridden in a derived class, gets the number of attributes on the current node.

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

属性值

当前节点上的属性数目。The number of attributes on the current node.

异常

在上一次异步操作完成之前调用了 XmlReader 方法。An XmlReader method was called before a previous asynchronous operation finished. 在此情况下,会引发 InvalidOperationException 并显示消息“异步操作已在进行中。”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.
  reader.MoveToElement(); 
}
' 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.
  reader.MoveToElement() 
End If

注解

此属性仅与Element DocumentTypeXmlDeclaration节点相关。This property is relevant to Element, DocumentType and XmlDeclaration nodes only. (其他节点类型不具有属性。)(Other node types do not have attributes.)

适用于