XmlReader.HasAttributes 屬性

定義

會取得一個值,表示目前節點是否有任何屬性。

public:
 virtual property bool HasAttributes { bool get(); };
public virtual bool HasAttributes { get; }
member this.HasAttributes : bool
Public Overridable ReadOnly Property HasAttributes As Boolean

屬性值

true如果目前節點有屬性;否則,。 false

例外狀況

在先前非同步操作結束前,會呼叫一個 XmlReader 方法。 此時, InvalidOperationException 會拋出「非同步操作已進行中」的訊息。

範例

以下範例顯示目前節點上的所有屬性。

if (reader.HasAttributes) {
  Console.WriteLine("Attributes of <" + reader.Name + ">");
  while (reader.MoveToNextAttribute()) {
    Console.WriteLine(" {0}={1}", reader.Name, reader.Value);
  }
  // Move the reader back to the element node.
  reader.MoveToElement();
}
If reader.HasAttributes Then
  Console.WriteLine("Attributes of <" + reader.Name + ">")
  While reader.MoveToNextAttribute()
    Console.WriteLine(" {0}={1}", reader.Name, reader.Value)
  End While
  ' Move the reader back to the element node.
  reader.MoveToElement()
End If

適用於