XElement.IsEmpty Property (System.Xml.Linq)

Switch View :
ScriptFree
.NET Framework Class Library
XElement.IsEmpty Property

Gets a value indicating whether this element contains no content.

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

Visual Basic
Public ReadOnly Property IsEmpty As Boolean
	Get
C#
public bool IsEmpty { get; }
Visual C++
public:
property bool IsEmpty {
	bool get ();
}
F#
member IsEmpty : bool

Property Value

Type: System.Boolean
true if this element contains no content; otherwise false.
Remarks

Note that an element that contains a start and end tag with no content between the tags is not considered to be an empty element. It has content with no length. Only an element that contains only a start tag, and is expressed as a terminated empty element, is considered to be empty.

Examples

The following example creates a variety of XML trees, and shows the value of this property with each tree.

C#
XElement el1 = new XElement("Root");
Console.WriteLine(el1);
Console.WriteLine(el1.IsEmpty);
Console.WriteLine();
XElement el2 = new XElement("Root", "content");
Console.WriteLine(el2);
Console.WriteLine(el2.IsEmpty);
Console.WriteLine();
XElement el3 = new XElement("Root", "");
Console.WriteLine(el3);
Console.WriteLine(el3.IsEmpty);
Console.WriteLine();
el3.ReplaceAll(null);
Console.WriteLine(el3);
Console.WriteLine(el3.IsEmpty);
Visual Basic
Dim el1 As XElement = <Root/>
Console.WriteLine(el1)
Console.WriteLine(el1.IsEmpty)
Console.WriteLine()
Dim el2 As XElement = <Root>content</Root>
Console.WriteLine(el2)
Console.WriteLine(el2.IsEmpty)
Console.WriteLine()
Dim el3 As XElement = <Root></Root>
Console.WriteLine(el3)
Console.WriteLine(el3.IsEmpty)
Console.WriteLine()
el3.ReplaceAll(Nothing)
Console.WriteLine(el3)
Console.WriteLine(el3.IsEmpty)

This example produces the following output:

<Root />
True

<Root>content</Root>
False

<Root></Root>
False

<Root />
True
Version Information

.NET Framework

Supported in: 4, 3.5

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Platforms

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

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

Reference

Other Resources