This documentation is archived and is not being maintained.

XmlElement.IsEmpty Property

Gets or sets the tag format of the element.

Namespace:  System.Xml
Assembly:  System.Xml (in System.Xml.dll)

public bool IsEmpty { get; set; }

Property Value

Type: System.Boolean
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).

The following example adds content to an empty element.

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);

  }
}
#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)
         currNode->InnerXml=S"19.95"; 

       Console::WriteLine(S"Display the modified XML...");
       Console::WriteLine(doc->OuterXml);
}

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0, 1.0

XNA Framework

Supported in: 3.0, 2.0, 1.0
Show: