Export (0) Print
Expand All

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)

'Declaration
Public MustOverride ReadOnly Property IsEmptyElement As Boolean

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.


Dim output As New StringBuilder()

Dim xmlString As String = _
        "<book>" & _
            "<title>Pride And Prejudice</title>" & _
            "<price>19.95</price>" & _
            "<misc/>" & _
        "</book>"

' Create an XmlReader
Using reader As XmlReader = XmlReader.Create(New StringReader(xmlString))

    While reader.Read()
        Select Case reader.NodeType
            Case XmlNodeType.Element
                If reader.IsEmptyElement Then
                    output.AppendLine(Environment.NewLine + "<" + reader.Name + "/>")
                Else
                    output.Append("<" + reader.Name + ">")
                End If
            Case XmlNodeType.Text
                output.Append(reader.Value)
            Case XmlNodeType.Document
            Case XmlNodeType.EndElement
                output.AppendLine("</" + reader.Name + ">")
        End Select
    End While
End Using
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