다음을 통해 공유


XElement.IsEmpty Property

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Gets a value indicating whether this element contains no content.

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

Syntax

'Declaration
Public ReadOnly Property IsEmpty As Boolean
public bool IsEmpty { get; }

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.

Dim output As New StringBuilder
Dim el1 As XElement = <Root/>
output.Append(el1)
output.Append(Environment.NewLine)
output.Append(el1.IsEmpty)
output.Append(Environment.NewLine)
Dim el2 As XElement = <Root>content</Root>
output.Append(el2)
output.Append(Environment.NewLine)
output.Append(el2.IsEmpty)
output.Append(Environment.NewLine)
Dim el3 As XElement = <Root></Root>
output.Append(el3)
output.Append(Environment.NewLine)
output.Append(el3.IsEmpty)
output.Append(Environment.NewLine)
el3.ReplaceAll(Nothing)
output.Append(el3)
output.Append(Environment.NewLine)
output.Append(el3.IsEmpty)
output.Append(Environment.NewLine)


OutputTextBlock.Text = output.ToString()
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();

Version Information

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

Platforms

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