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

定义

测试当前内容节点是否是开始标记。Tests if the current content node is a start tag.

重载

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

调用 MoveToContent() 并测试当前内容节点是否是开始标记或空元素标记,以及所找到元素的 LocalNameNamespaceURI 属性是否与给定的字符串匹配。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()

调用 MoveToContent() 并测试当前内容节点是否是开始标记或空元素标记。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)

调用 MoveToContent() 并测试当前内容节点是否是开始标记或空元素标记,以及所找到元素的 Name 属性是否与给定的参数匹配。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)

调用 MoveToContent() 并测试当前内容节点是否是开始标记或空元素标记,以及所找到元素的 LocalNameNamespaceURI 属性是否与给定的字符串匹配。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

参数

localname
String String String String

与找到的元素的 LocalName 属性匹配的字符串。The string to match against the LocalName property of the element found.

ns
String String String String

与找到的元素的 NamespaceURI 属性匹配的字符串。The string to match against the NamespaceURI property of the element found.

返回

如果生成的节点是一个元素,则为 truetrue if the resulting node is an element. 如果找到 false 之外的节点类型,或者元素的 XmlNodeType.ElementLocalName 属性与指定的字符串不匹配,则为 NamespaceURIfalse 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.

异常

在输入流中遇到不正确的 XML。Incorrect XML is encountered in the input stream.

在上一次异步操作完成之前调用了 XmlReader 方法。An XmlReader method was called before a previous asynchronous operation finished. 在此情况下,会引发 InvalidOperationException 并显示消息“异步操作已在进行中。”In this case, InvalidOperationException is thrown with the message "An asynchronous operation is already in progress."

注解

此方法将跳过空格、 注释和处理指令之前读取器定位在某个内容节点上。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.

另请参阅

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

调用 MoveToContent() 并测试当前内容节点是否是开始标记或空元素标记。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

返回

如果 MoveToContent() 找到开始标记或空元素标记,则为 true;如果找到不同于 false 的节点类型,则为 XmlNodeType.Elementtrue if MoveToContent() finds a start tag or empty element tag; false if a node type other than XmlNodeType.Element was found.

异常

在输入流中遇到不正确的 XML。Incorrect XML is encountered in the input stream.

在上一次异步操作完成之前调用了 XmlReader 方法。An XmlReader method was called before a previous asynchronous operation finished. 在此情况下,会引发 InvalidOperationException 并显示消息“异步操作已在进行中。”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.
    }
  } 
} 
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

该示例使用该文件,elems.xml作为输入。The example uses the file, elems.xml, as input.

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

注解

此方法将跳过空格、 注释和处理指令之前读取器定位在某个内容节点上。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.

另请参阅

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

调用 MoveToContent() 并测试当前内容节点是否是开始标记或空元素标记,以及所找到元素的 Name 属性是否与给定的参数匹配。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

参数

name
String String String String

与找到的元素的 Name 属性匹配的字符串。The string matched against the Name property of the element found.

返回

如果生成的节点是一个元素,且 true 属性与指定的字符串匹配,则为 Nametrue if the resulting node is an element and the Name property matches the specified string. 如果找到 false 之外的节点类型,或者元素的 XmlNodeType.Element 属性与指定的字符串不匹配,则为 Namefalse if a node type other than XmlNodeType.Element was found or if the element Name property does not match the specified string.

异常

在输入流中遇到不正确的 XML。Incorrect XML is encountered in the input stream.

在上一次异步操作完成之前调用了 XmlReader 方法。An XmlReader method was called before a previous asynchronous operation finished. 在此情况下,会引发 InvalidOperationException 并显示消息“异步操作已在进行中。”In this case, InvalidOperationException is thrown with the message "An asynchronous operation is already in progress."

示例

下面的示例显示每个价格元素。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

注解

此方法将跳过空格、 注释和处理指令之前读取器定位在某个内容节点上。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.

另请参阅

适用于