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,将更改属性值(无论元素是否有内容);如果该元素为空,则会采用长格式序列化。
此属性是文档对象模型 (DOM) 的 Microsoft 扩展。
示例
以下示例将内容添加到空元素。
#using <System.Xml.dll>
using namespace System;
using namespace System::Xml;
int main()
{
   XmlDocument^ doc = gcnew XmlDocument;
   doc->LoadXml( "<book>  <title>Pride And Prejudice</title>  <price/></book>" );
   XmlElement^ currNode = dynamic_cast<XmlElement^>(doc->DocumentElement->LastChild);
   if ( currNode->IsEmpty )
      currNode->InnerXml = "19.95";
   Console::WriteLine( "Display the modified XML..." );
   Console::WriteLine( doc->OuterXml );
}
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 扩展。