XmlWriter.WriteEndElement メソッド

定義

派生クラスでオーバーライドされると、1 つの要素を閉じ、対応する名前空間スコープをポップします。When overridden in a derived class, closes one element and pops the corresponding namespace scope.

public:
 abstract void WriteEndElement();
public abstract void WriteEndElement ();
abstract member WriteEndElement : unit -> unit
Public MustOverride Sub WriteEndElement ()

例外

結果が無効な XML ドキュメントになります。This results in an invalid XML document.

- または --or-

先行の非同期操作が完了する前に、XmlWriter メソッドが呼び出されました。An XmlWriter 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."

次の例では、WriteEndElementWriteFullEndElement メソッドを使用します。The following example uses the WriteEndElement and the WriteFullEndElement methods.

using System;
using System.IO;
using System.Xml;

public class Sample {

  public static void Main() {
  
     // Create a writer to write XML to the console.
     XmlWriterSettings settings = new XmlWriterSettings();
     settings.Indent = true;
     XmlWriter writer = XmlWriter.Create(Console.Out, settings);

     // Write the root element.
     writer.WriteStartElement("order");

     // Write an element with attributes.
     writer.WriteStartElement("item");
     writer.WriteAttributeString("date", "2/19/01");
     writer.WriteAttributeString("orderID", "136A5");

     // Write a full end element. Because this element has no
     // content, calling WriteEndElement would have written a
     // short end tag '/>'.
     writer.WriteFullEndElement();

     writer.WriteEndElement();
             
     // Write the XML to file and close the writer
     writer.Close();  
  }
}
Option Explicit
Option Strict

Imports System.IO
Imports System.Xml

Public Class Sample
    
  Public Shared Sub Main()

     ' Create a writer to write XML to the console.
     Dim settings As XmlWriterSettings = new XmlWriterSettings()
     settings.Indent = true
     Dim writer As XmlWriter = XmlWriter.Create(Console.Out, settings)
        
     ' Write the root element.
     writer.WriteStartElement("order")
        
     ' Write an element with attributes.
     writer.WriteStartElement("item")
     writer.WriteAttributeString("date", "2/19/01")
     writer.WriteAttributeString("orderID", "136A5")
        
     ' Write a full end element. Because this element has no
     ' content, calling WriteEndElement would have written a
     ' short end tag '/>'.
     writer.WriteFullEndElement()
        
     writer.WriteEndElement()

     ' Write the XML to file and close the writer
     writer.Close()

    End Sub
End Class

注釈

要素にコンテンツが含まれていない場合は、短い終了タグ "/>" が書き込まれます。それ以外の場合は、完全終了タグが書き込まれます。If the element contains no content, a short end tag "/>" is written; otherwise, a full end tag is written.

注意

XmlWriter メソッドを使用して XML を出力する場合、Close メソッドを呼び出すまで、要素と属性は書き込まれません。When you use the XmlWriter methods to output XML, the elements and attributes will not be written until you call the Close method. たとえば、XmlWriter を使用して XmlDocumentを設定している場合、XmlWriterを閉じるまで、ターゲットドキュメント内の記述された要素と属性を確認することはできません。For example, if you are using the XmlWriter to populate an XmlDocument, until you close the XmlWriter, you will not be able to observe the written elements and attributes in the target document.

このメソッドの非同期バージョンについては、「WriteEndElementAsync」を参照してください。For the asynchronous version of this method, see WriteEndElementAsync.

適用対象