IsEmptyElement Property

XmlReader.IsEmptyElement Property

When overridden in a derived class, gets a value indicating whether the current node is an empty element (for example, <MyElement/>).

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

public abstract bool IsEmptyElement { get; }

Property Value

Type: System.Boolean
true if the current node is an element (NodeType equals XmlNodeType.Element) that ends with />; otherwise, false.

This property enables you to determine the difference between the following:

<item num="123"/> (IsEmptyElement is true).

<item num="123"></item> (IsEmptyElement is false, although element content is empty).

A corresponding EndElement node is not generated for empty elements.

StringBuilder output = new StringBuilder();

String xmlString =
      <title>Pride And Prejudice</title>

// Create an XmlReader
using (XmlReader reader = XmlReader.Create(new StringReader(xmlString)))
    while (reader.Read())
        switch (reader.NodeType)
            case XmlNodeType.Element:
                if (reader.IsEmptyElement)
                    output.AppendLine(Environment.NewLine + "<" + reader.Name + "/>");
                    output.Append("<" + reader.Name + ">");
            case XmlNodeType.Text:
            case XmlNodeType.Document:
            case XmlNodeType.EndElement:
                output.AppendLine("</" + reader.Name + ">");

OutputTextBlock.Text = output.ToString();


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.

Ajouts de la communauté

© 2015 Microsoft