XmlReader.ReadEndElement Method

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

Checks that the current content node is an end tag and advances the reader to the next node.

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

Syntax

'Declaration
Public Overridable Sub ReadEndElement
public virtual void ReadEndElement()

Exceptions

Exception Condition
XmlException

The current node is not an end tag or if incorrect XML is encountered in the input stream.

Examples

Dim output As New StringBuilder()

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

Using reader As XmlReader = XmlReader.Create(New StringReader(xmlString))
    ' Parse the XML document. 
    reader.Read()
    reader.ReadStartElement("book")
    reader.ReadStartElement("title")
    output.AppendLine("The content of the title element:  ")
    output.AppendLine(reader.ReadContentAsString())
    reader.ReadContentAsString()
    reader.ReadEndElement()
    reader.ReadStartElement("price")
    output.AppendLine("The content of the price element:  ")
    output.AppendLine(reader.ReadContentAsDouble().ToString())
    reader.ReadEndElement()
    reader.ReadEndElement()
End Using

OutputTextBlock.Text = output.ToString()

StringBuilder output = new StringBuilder();

String xmlString =
    @"<book>
    <title>Pride And Prejudice</title>
    <price>19.95</price>
</book>";

using (XmlReader reader = XmlReader.Create(new StringReader(xmlString)))
{
    // Parse the XML document. 
    reader.Read();
    reader.ReadStartElement("book");
    reader.ReadStartElement("title");
    output.AppendLine("The content of the title element:  ");
    output.AppendLine(reader.ReadContentAsString());
    reader.ReadEndElement();
    reader.ReadStartElement("price");
    output.AppendLine("The content of the price element:  ");
    output.AppendLine(reader.ReadContentAsDouble().ToString());
    reader.ReadEndElement();
    reader.ReadEndElement();

}

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.