XmlReader.ReadStartElement XmlReader.ReadStartElement XmlReader.ReadStartElement XmlReader.ReadStartElement Method

定义

检查当前节点是否为元素并将读取器推进到下一个节点。Checks that the current node is an element and advances the reader to the next node.

重载

ReadStartElement() ReadStartElement() ReadStartElement() ReadStartElement()

检查当前节点是否为元素并将读取器推进到下一个节点。Checks that the current node is an element and advances the reader to the next node.

ReadStartElement(String) ReadStartElement(String) ReadStartElement(String) ReadStartElement(String)

检查当前内容节点是否为具有给定 Name 的元素并将读取器推进到下一个节点。Checks that the current content node is an element with the given Name and advances the reader to the next node.

ReadStartElement(String, String) ReadStartElement(String, String) ReadStartElement(String, String) ReadStartElement(String, String)

检查当前内容节点是否为具有给定 LocalNameNamespaceURI 的元素并将读取器推进到下一个节点。Checks that the current content node is an element with the given LocalName and NamespaceURI and advances the reader to the next node.

ReadStartElement() ReadStartElement() ReadStartElement() ReadStartElement()

检查当前节点是否为元素并将读取器推进到下一个节点。Checks that the current node is an element and advances the reader to the next node.

public:
 virtual void ReadStartElement();
public virtual void ReadStartElement ();
abstract member ReadStartElement : unit -> unit
override this.ReadStartElement : unit -> unit
Public Overridable Sub ReadStartElement ()

异常

在输入流中遇到不正确的 XML。Incorrect XML was 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."

注解

此方法调用IsStartElementRead以定位您在输入流中找到该元素的内容上。This method calls IsStartElement followed by Read to position you on the content of that element found in the input stream.

另请参阅

ReadStartElement(String) ReadStartElement(String) ReadStartElement(String) ReadStartElement(String)

检查当前内容节点是否为具有给定 Name 的元素并将读取器推进到下一个节点。Checks that the current content node is an element with the given Name and advances the reader to the next node.

public:
 virtual void ReadStartElement(System::String ^ name);
public virtual void ReadStartElement (string name);
abstract member ReadStartElement : string -> unit
override this.ReadStartElement : string -> unit
Public Overridable Sub ReadStartElement (name As String)

参数

name
String String String String

元素的限定名。The qualified name of the element.

异常

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

- 或 --or- 元素的 Name 不匹配给定的 nameThe Name of the element does not match the given name.

在上一次异步操作完成之前调用了 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.

using (XmlReader reader = XmlReader.Create("book3.xml")) {

  // Parse the XML document.  ReadString is used to 
  // read the text content of the elements.
  reader.Read(); 
  reader.ReadStartElement("book");  
  reader.ReadStartElement("title");   
  Console.Write("The content of the title element:  ");
  Console.WriteLine(reader.ReadString());
  reader.ReadEndElement();
  reader.ReadStartElement("price");
  Console.Write("The content of the price element:  ");
  Console.WriteLine(reader.ReadString());
  reader.ReadEndElement();
  reader.ReadEndElement();

}
Using reader As XmlReader = XmlReader.Create("book3.xml")               
  ' Parse the XML document.  ReadString is used to 
  ' read the text content of the elements.
  reader.Read()
  reader.ReadStartElement("book")
  reader.ReadStartElement("title")
  Console.Write("The content of the title element:  ")
  Console.WriteLine(reader.ReadString())
  reader.ReadEndElement()
  reader.ReadStartElement("price")
  Console.Write("The content of the price element:  ")
  Console.WriteLine(reader.ReadString())
  reader.ReadEndElement()
  reader.ReadEndElement()            
End Using

该示例使用book3.xml文件。The example uses the book3.xml file.

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

注解

调用此方法对应于调用IsStartElement调用后跟ReadA call to this method corresponds to a call to IsStartElement followed by a call to Read.

另请参阅

ReadStartElement(String, String) ReadStartElement(String, String) ReadStartElement(String, String) ReadStartElement(String, String)

检查当前内容节点是否为具有给定 LocalNameNamespaceURI 的元素并将读取器推进到下一个节点。Checks that the current content node is an element with the given LocalName and NamespaceURI and advances the reader to the next node.

public:
 virtual void ReadStartElement(System::String ^ localname, System::String ^ ns);
public virtual void ReadStartElement (string localname, string ns);
abstract member ReadStartElement : string * string -> unit
override this.ReadStartElement : string * string -> unit
Public Overridable Sub ReadStartElement (localname As String, ns As String)

参数

localname
String String String String

元素的本地名称。The local name of the element.

ns
String String String String

元素的命名空间 URI。The namespace URI of the element.

异常

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

- 或 --or- 所找到元素的 LocalNameNamespaceURI 属性与给定的参数不匹配。The LocalName and NamespaceURI properties of the element found do not match the given arguments.

在上一次异步操作完成之前调用了 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."

注解

调用此方法对应于调用IsStartElement调用后跟ReadA call to this method corresponds to a call to IsStartElement followed by a call to Read.

另请参阅

适用于