Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

XmlReader.ReadStartElement Method (String)

Checks that the current content node is an element with the given Name and advances the reader to the next node.

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

public virtual void ReadStartElement(
	string name
)

Parameters

name
Type: System.String
The qualified name of the element.

ExceptionCondition
XmlException

IsStartElement returns false or if 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.



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();


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.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2015 Microsoft