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 */
public boolean get_IsEmpty ()

/** @property */
public void set_IsEmpty (boolean value)

public function get IsEmpty () : boolean

public function set IsEmpty (value : 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).

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();
                  "  <title>Pride And Prejudice</title>" +
                  "  <price/>" +
      XmlElement currNode = (XmlElement) doc.DocumentElement.LastChild;
      if (currNode.IsEmpty)

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


import System.*;
import System.Xml.*;

public class Sample
    public static void main(String[] args)
        XmlDocument doc = new XmlDocument();
            + "<title>Pride And Prejudice</title>"
            + "<price/>"
            + "</book>");

        XmlElement currNode = 
        if (currNode.get_IsEmpty()) {

        Console.WriteLine("Display the modified XML...");
    } //main 
} //Sample

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

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

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0