XmlReader.ReadEndElement XmlReader.ReadEndElement XmlReader.ReadEndElement XmlReader.ReadEndElement Method

定义

检查当前内容节点是否为结束标记并将读取器推进到下一个节点。Checks that the current content node is an end tag and advances the reader to the next node.

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

异常

当前节点不是一个结束标记,或者如果在输入流中遇到不正确的 XML。The current node is not an end tag or if 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.

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>

适用于

另请参阅