XmlReader.IsStartElement Method
Calls MoveToContent and tests if the current content node is a start tag or empty element tag.
Namespace: System.Xml
Assembly: System.Xml (in System.Xml.dll)
Return Value
Type: System.Booleantrue if MoveToContent finds a start tag or empty element tag; false if a node type other than XmlNodeType.Element was found.
| Exception | Condition |
|---|---|
| XmlException | Incorrect XML is encountered in the input stream. |
| InvalidOperationException | An XmlReader method was called before a previous asynchronous operation finished. In this case, InvalidOperationException is thrown with the message “An asynchronous operation is already in progress.” |
The following example displays the text content of each element.
while (reader.Read()) { if (reader.IsStartElement()) { if (reader.IsEmptyElement) Console.WriteLine("<{0}/>", reader.Name); else { Console.Write("<{0}> ", reader.Name); reader.Read(); // Read the start tag. if (reader.IsStartElement()) // Handle nested elements. Console.Write("\r\n<{0}>", reader.Name); Console.WriteLine(reader.ReadString()); //Read the text content of the element. } } }
The example uses the file, elems.xml, as input.
<book> <title>Pride And Prejudice</title> <price>19.95</price> <misc/> </book>
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.