XmlElement.HasAttributes 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
會取得 boolean 一個值,表示目前節點是否有任何屬性。
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
範例
以下範例將根元素中的所有屬性移除。
using System;
using System.IO;
using System.Xml;
public class Sample
{
public static void Main()
{
XmlDocument doc = new XmlDocument();
doc.LoadXml("<book genre='novel' ISBN='1-861001-57-5'>" +
"<title>Pride And Prejudice</title>" +
"</book>");
XmlElement root = doc.DocumentElement;
// Remove all attributes from the root element.
if (root.HasAttributes)
root.RemoveAllAttributes();
Console.WriteLine("Display the modified XML...");
Console.WriteLine(doc.InnerXml);
}
}
Imports System.IO
Imports System.Xml
public class Sample
public shared sub Main()
Dim doc as XmlDocument = new XmlDocument()
doc.LoadXml("<book genre='novel' ISBN='1-861001-57-5'>" & _
"<title>Pride And Prejudice</title>" & _
"</book>")
Dim root as XmlElement = doc.DocumentElement
' Remove all attributes.
if (root.HasAttributes)
root.RemoveAllAttributes()
end if
Console.WriteLine("Display the modified XML...")
Console.WriteLine(doc.InnerXml)
end sub
end class
備註
此屬性是 Microsoft 對文件物件模型(DOM)的擴充。