Export (0) Print
Expand All

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)

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


Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Community Additions

ADD
Show:
© 2014 Microsoft