XmlElement.IsEmpty 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定元素的標籤格式。
public:
property bool IsEmpty { bool get(); void set(bool value); };
public bool IsEmpty { get; set; }
member this.IsEmpty : bool with get, set
Public Property IsEmpty As Boolean
屬性值
true 若元素需以短標籤格式序列化為「<item/>」; false 若為長格式為「<item></item>」。
當設定此屬性時,若將 設為 true,元素的子節點會被移除,元素會以短標籤格式序列化。 若設為 false,則屬性值會改變(無論元素是否有內容);若元素為空,則以長格式序列化。
此屬性是 Microsoft 對文件物件模型(DOM)的擴充。
範例
以下範例將內容加入空元素。
using System;
using System.Xml;
public class Sample {
public static void Main() {
XmlDocument doc = new XmlDocument();
doc.LoadXml("<book>"+
" <title>Pride And Prejudice</title>" +
" <price/>" +
"</book>");
XmlElement currNode = (XmlElement) doc.DocumentElement.LastChild;
if (currNode.IsEmpty)
currNode.InnerXml="19.95";
Console.WriteLine("Display the modified XML...");
Console.WriteLine(doc.OuterXml);
}
}
Imports System.Xml
public class Sample
public shared sub Main()
Dim doc as XmlDocument = new XmlDocument()
doc.LoadXml("<book>" & _
" <title>Pride And Prejudice</title>" & _
" <price/>" & _
"</book>")
Dim currNode as XmlElement
currNode = CType (doc.DocumentElement.LastChild, XmlElement)
if (currNode.IsEmpty)
currNode.InnerXml="19.95"
end if
Console.WriteLine("Display the modified XML...")
Console.WriteLine(doc.OuterXml)
end sub
end class
備註
此屬性是 Microsoft 對文件物件模型(DOM)的擴充。