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)

Not applicable.

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

  }
}

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

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

        XmlElement currNode = 
            (XmlElement)doc.get_DocumentElement().get_LastChild();
        if (currNode.get_IsEmpty()) {
            currNode.set_InnerXml("19.95");
        }

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

Windows 98, Windows Server 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 Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

XNA Framework

Supported in: 1.0
Show: