Tests if the current content node is a start tag.
Overload List
Calls MoveToContent and tests if the current content node is a start tag or empty element tag.
Supported by the .NET Compact Framework.
[Visual Basic] Overloads Public Overridable Function IsStartElement() As Boolean
[C#] public virtual bool IsStartElement();
[C++] public: virtual bool IsStartElement();
[JScript] public function IsStartElement() : Boolean;
Calls MoveToContent and tests if the current content node is a start tag or empty element tag and if the Name property of the element found matches the given argument.
Supported by the .NET Compact Framework.
[Visual Basic] Overloads Public Overridable Function IsStartElement(String) As Boolean
[C#] public virtual bool IsStartElement(string);
[C++] public: virtual bool IsStartElement(String*);
[JScript] public function IsStartElement(String) : Boolean;
Calls MoveToContent and tests if the current content node is a start tag or empty element tag and if the LocalName and NamespaceURI properties of the element found match the given strings.
Supported by the .NET Compact Framework.
[Visual Basic] Overloads Public Overridable Function IsStartElement(String, String) As Boolean
[C#] public virtual bool IsStartElement(string, string);
[C++] public: virtual bool IsStartElement(String*, String*);
[JScript] public function IsStartElement(String, String) : Boolean;
Example
[Visual Basic, C#, C++] The following example displays the text content of each element.
[Visual Basic, C#, C++] Note This example shows how to use one of the overloaded versions of IsStartElement. For other examples that might be available, see the individual overload topics.
[Visual Basic]
Option Strict
Option Explicit
Imports System
Imports System.IO
Imports System.Xml
Public Class Sample
Public Shared Sub Main()
Dim reader As XmlTextReader = Nothing
Try
'Load the reader with the XML file.
reader = New XmlTextReader("elems.xml")
'Parse the XML and display the text content of each of the elements.
While reader.Read()
If reader.IsStartElement() Then
If reader.IsEmptyElement Then
Console.WriteLine("<{0}/>", reader.Name)
Else
Console.Write("<{0}>" + " ", reader.Name)
reader.Read() 'Read the start tag.
If (reader.IsStartElement()) 'Handle nested elements.
Console.WriteLine()
Console.Write("<{0}>", reader.Name)
End If
Console.WriteLine(reader.ReadString()) 'Read the text content of the element.
End If
End If
End While
Finally
If Not (reader Is Nothing) Then
reader.Close()
End If
End Try
End Sub 'Main
End Class 'Sample
[C#]
using System;
using System.IO;
using System.Xml;
public class Sample
{
public static void Main()
{
XmlTextReader reader = null;
try
{
//Load the reader with the XML file.
reader = new XmlTextReader("elems.xml");
//Parse the XML and display the text content of each of the elements.
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.
}
}
}
}
finally
{
if (reader != null)
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()
{
XmlTextReader* reader = 0;
try
{
//Load the reader with the XML file.
reader = new XmlTextReader(S"elems.xml");
//Parse the XML and display the text content of each of the elements.
while (reader->Read()){
if (reader->IsStartElement()){
if (reader->IsEmptyElement)
Console::WriteLine(S"<{0}/>", reader->Name);
else{
Console::Write(S"<{0}> ", reader->Name);
reader->Read(); //Read the start tag.
if (reader->IsStartElement()) //Handle nested elements.
Console::Write(S"\r\n<{0}>", reader->Name);
Console::WriteLine(reader->ReadString()); //Read the text content of the element.
}
}
}
}
__finally
{
if (reader != 0)
reader->Close();
}
}
The example uses the file, elems.xml, as input.
<book>
<title>Pride And Prejudice</title>
<price>19.95</price>
<misc/>
</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.
See Also
XmlReader Class | XmlReader Members | System.Xml Namespace