IsEmpty Property
Collapse the table of content
Expand the table of content

XElement.IsEmpty Property

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

Gets a value indicating whether this element contains no content.

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

public bool IsEmpty { get; }

Property Value

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

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.

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


StringBuilder output = new StringBuilder();
XElement el1 = new XElement("Root");
output.Append(el1 + Environment.NewLine);
output.Append(el1.IsEmpty + Environment.NewLine);
output.Append(Environment.NewLine);
XElement el2 = new XElement("Root", "content");
output.Append(el2 + Environment.NewLine);
output.Append(el2.IsEmpty + Environment.NewLine);
output.Append(Environment.NewLine);
XElement el3 = new XElement("Root", "");
output.Append(el3 + Environment.NewLine);
output.Append(el3.IsEmpty + Environment.NewLine);
output.Append(Environment.NewLine);
el3.ReplaceAll(null);
output.Append(el3 + Environment.NewLine);
output.Append(el3.IsEmpty + Environment.NewLine);

OutputTextBlock.Text = output.ToString();


Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2017 Microsoft