Прочетете на английски Редактиране

Споделяне чрез


XmlReader.IsStartElement Method

Definition

Tests if the current content node is a start tag.

Overloads

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

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

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)

Source:
XmlReader.cs
Source:
XmlReader.cs
Source:
XmlReader.cs

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 (string localname, string ns);

Parameters

localname
String

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

ns
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

Applies to

.NET 9 и други версии
Продукт Версии
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

IsStartElement()

Source:
XmlReader.cs
Source:
XmlReader.cs
Source:
XmlReader.cs

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

public virtual bool IsStartElement ();

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

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

Applies to

.NET 9 и други версии
Продукт Версии
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

IsStartElement(String)

Source:
XmlReader.cs
Source:
XmlReader.cs
Source:
XmlReader.cs

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

Parameters

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

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

.NET 9 и други версии
Продукт Версии
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0