XmlReader.IsStartElement XmlReader.IsStartElement XmlReader.IsStartElement XmlReader.IsStartElement Method

Definition

Tests if the current content node is a start tag.

Overloads

IsStartElement(String, String) IsStartElement(String, String) IsStartElement(String, String) IsStartElement(String, String)

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.

IsStartElement() IsStartElement() IsStartElement() IsStartElement()

Calls MoveToContent() and tests if the current content node is a start tag or empty element tag.

IsStartElement(String) IsStartElement(String) IsStartElement(String) IsStartElement(String)

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.

IsStartElement(String, String) IsStartElement(String, String) IsStartElement(String, String) IsStartElement(String, String)

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.

public:
 virtual bool IsStartElement(System::String ^ localname, System::String ^ ns);
public virtual bool IsStartElement (string localname, string ns);
abstract member IsStartElement : string * string -> bool
override this.IsStartElement : string * string -> bool
Public Overridable Function IsStartElement (localname As String, ns As String) As Boolean

Parameters

localname
String String String String

The string to match against the LocalName property of the element found.

ns
String String String String

The string to match against the NamespaceURI property of the element found.

Returns

true if the resulting node is an element. false if a node type other than XmlNodeType.Element was found or if the LocalName and NamespaceURI properties of the element do not match the specified strings.

Exceptions

Incorrect XML is encountered in the input stream.

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."

Remarks

This method skips white space, comments, and processing instructions until the reader is positioned on a content node. The method then tests if the current node is an element.

See also

IsStartElement() IsStartElement() IsStartElement() IsStartElement()

Calls MoveToContent() and tests if the current content node is a start tag or empty element tag.

public:
 virtual bool IsStartElement();
public virtual bool IsStartElement ();
abstract member IsStartElement : unit -> bool
override this.IsStartElement : unit -> bool
Public Overridable Function IsStartElement () As Boolean

Returns

true if MoveToContent() finds a start tag or empty element tag; false if a node type other than XmlNodeType.Element was found.

Exceptions

Incorrect XML is encountered in the input stream.

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."

Examples

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.
    }
  } 
} 
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() Then ' Handle nested elements.
        Console.Write(vbCr + vbLf + "<{0}>", reader.Name)
      End If
      Console.WriteLine(reader.ReadString()) 'Read the text content of the element.
    End If
  End If
End While

The example uses the file, elems.xml, as input.

<book>
  <title>Pride And Prejudice</title>
  <price>19.95</price>
  <misc/>
</book>

Remarks

This method skips white space, comments, and processing instructions until the reader is positioned on a content node. The method then tests if the current node is an element.

See also

IsStartElement(String) IsStartElement(String) IsStartElement(String) IsStartElement(String)

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.

public:
 virtual bool IsStartElement(System::String ^ name);
public virtual bool IsStartElement (string name);
abstract member IsStartElement : string -> bool
override this.IsStartElement : string -> bool
Public Overridable Function IsStartElement (name As String) As Boolean

Parameters

name
String String String String

The string matched against the Name property of the element found.

Returns

true if the resulting node is an element and the Name property matches the specified string. false if a node type other than XmlNodeType.Element was found or if the element Name property does not match the specified string.

Exceptions

Incorrect XML is encountered in the input stream.

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."

Examples

The following example displays each price element.

// Parse the file and display each price node.
while (reader.Read()) {
  if (reader.IsStartElement("price")) {
     Console.WriteLine(reader.ReadInnerXml());
  }
}   
' Parse the file and display each price node.
While reader.Read()
  If reader.IsStartElement("price") Then
    Console.WriteLine(reader.ReadInnerXml())
  End If
End While

Remarks

This method skips white space, comments, and processing instructions until the reader is positioned on a content node. The method then tests if the current node is an element.

See also

Applies to