This documentation is archived and is not being maintained.

XmlElement.IsEmpty Property

Gets or sets the tag format of the element.

[Visual Basic]
Public Property IsEmpty As Boolean
public bool IsEmpty {get; set;}
public: __property bool get_IsEmpty();
public: __property void set_IsEmpty(bool);
public function get IsEmpty() : Boolean;
public function set IsEmpty(Boolean);

Property Value

Returns true if the element is to be serialized in the short tag format "<item/>"; false for the long format "<item></item>".

When setting this property, if set to true, the children of the element are removed and the element is serialized in the short tag format. If set to false, the value of the property is changed (regardless of whether or not the element has content); if the element is empty, it is serialized in the long format.

This property is a Microsoft extension to the Document Object Model (DOM).


This property is a Microsoft extension of the Document Object Model (DOM).


[Visual Basic, C#, C++] The following example adds content to an empty element.

[Visual Basic] 
Imports System
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/>" & _

      Dim currNode as XmlElement 
      currNode = CType (doc.DocumentElement.LastChild, XmlElement)
      if (currNode.IsEmpty)
      end if

      Console.WriteLine("Display the modified XML...")

  end sub
end class

using System;
using System.Xml;

public class Sample {

  public static void Main() {

      XmlDocument doc = new XmlDocument();
                  "  <title>Pride And Prejudice</title>" +
                  "  <price/>" +
      XmlElement currNode = (XmlElement) doc.DocumentElement.LastChild;
      if (currNode.IsEmpty)

      Console.WriteLine("Display the modified XML...");


#using <mscorlib.dll>
#using <System.Xml.dll>
using namespace System;
using namespace System::Xml;

int main()
       XmlDocument* doc = new XmlDocument();
       doc->LoadXml(S"<book>  <title>Pride And Prejudice</title>  <price/></book>");     
       XmlElement* currNode = dynamic_cast<XmlElement*> (doc->DocumentElement->LastChild);
       if (currNode->IsEmpty)
       Console::WriteLine(S"Display the modified XML...");

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.


Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

See Also

XmlElement Class | XmlElement Members | System.Xml Namespace