XmlElement.IsEmpty Property


The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

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();
                  "  <title>Pride And Prejudice</title>" +
                  "  <price/>" +

      XmlElement currNode = (XmlElement) doc.DocumentElement.LastChild;
      if (currNode.IsEmpty)

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


Universal Windows Platform
Available since 10
.NET Framework
Available since 1.1
Return to top