Checks that the current content node is an end tag and advances the reader to the next node.
[Visual Basic]
Public Overridable Sub ReadEndElement()
[C#]
public virtual void ReadEndElement();
[C++]
public: virtual void ReadEndElement();
[JScript]
public function ReadEndElement();
Exceptions
| Exception Type | Condition |
| XmlException | The current node is not an end tag or if incorrect XML is encountered in the input stream. |
Example
[Visual Basic, C#, C++] The following example reads an XML document using the ReadStartElement and ReadEndElement methods.
[Visual Basic]
Imports System
Imports System.IO
Imports System.Xml
public class Sample
public shared sub Main()
'Create the reader.
Dim reader as XmlTextReader = new XmlTextReader("book3.xml")
'Parse the XML document. ReadString is used to
'read the text content of the elements.
reader.Read()
reader.ReadStartElement("book")
reader.ReadStartElement("title")
Console.Write("The content of the title element: ")
Console.WriteLine(reader.ReadString())
reader.ReadEndElement()
reader.ReadStartElement("price")
Console.Write("The content of the price element: ")
Console.WriteLine(reader.ReadString())
reader.ReadEndElement()
reader.ReadEndElement()
'Close the reader.
reader.Close()
end sub
end class
[C#]
using System;
using System.IO;
using System.Xml;
public class Sample
{
public static void Main()
{
//Create the reader.
XmlTextReader reader = new XmlTextReader("book3.xml");
//Parse the XML document. ReadString is used to
//read the text content of the elements.
reader.Read();
reader.ReadStartElement("book");
reader.ReadStartElement("title");
Console.Write("The content of the title element: ");
Console.WriteLine(reader.ReadString());
reader.ReadEndElement();
reader.ReadStartElement("price");
Console.Write("The content of the price element: ");
Console.WriteLine(reader.ReadString());
reader.ReadEndElement();
reader.ReadEndElement();
//Close the reader.
reader.Close();
}
} // End class
[C++]
#using <mscorlib.dll>
#using <System.Xml.dll>
using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{
// Create the reader.
XmlTextReader* reader = new XmlTextReader(S"book3.xml");
// Parse the XML document. ReadString is used to
// read the text content of the elements.
reader -> Read();
reader -> ReadStartElement(S"book");
reader -> ReadStartElement(S"title");
Console::Write(S"The content of the title element: ");
Console::WriteLine(reader -> ReadString());
reader -> ReadEndElement();
reader -> ReadStartElement(S"price");
Console::Write(S"The content of the price element: ");
Console::WriteLine(reader -> ReadString());
reader -> ReadEndElement();
reader -> ReadEndElement();
// Close the reader.
reader -> Close();
}
The example uses the file, book3.xml, as input.
<book>
<title>Pride And Prejudice</title>
<price>19.95</price>
</book>
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard
See Also
XmlReader Class | XmlReader Members | System.Xml Namespace | ReadStartElement