XmlReader.ReadStartElement Method (String)
.NET Framework 4
Checks that the current content node is an element with the given Name and advances the reader to the next node.
Assembly: System.Xml (in System.Xml.dll)
Parameters
- name
- Type: System.String
The qualified name of the element.
| Exception | Condition |
|---|---|
| XmlException | Incorrect XML was encountered in the input stream. -or- The Name of the element does not match the given name. |
A call to this method corresponds to a call to IsStartElement followed by a call to Read.
The following example displays the text content of each element.
using (XmlReader reader = XmlReader.Create("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(); }
The example uses the book3.xml file.
<book> <title>Pride And Prejudice</title> <price>19.95</price> </book>
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.