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/”进行序列化,<则为长格式“>item/itemfalse<”。><>
设置此属性时,如果设置为 true,则删除元素的子级,并且元素以短标记格式序列化。 如果设置为 false,则属性的值将更改(无论元素是否包含内容);如果该元素为空,则以长格式序列化该元素。
此属性是文档对象模型(DOM)的Microsoft扩展。
示例
以下示例将内容添加到空元素。
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
注解
此属性是文档对象模型(DOM)的Microsoft扩展。