共用方式為


XmlWriter.WriteFullEndElement 方法

定義

在衍生類別中覆寫時,關閉一個項目並取出對應的命名空間範圍。

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

例外狀況

在先前的非同步作業完成前呼叫了 XmlWriter 方法。 在此情況下,會擲回 InvalidOperationException 與「非同步作業已經在進行中」的訊息。

範例

下列範例會使用 WriteEndElementWriteFullEndElement 方法。

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

備註

這個方法一律會寫入完整的結束標記。 這在處理必須包含完整結束標記的專案時很有用。 例如,瀏覽器預期 HTML 腳本區塊會以 「 < /script > 」 關閉。

如需這個方法的非同步版本,請參閱 WriteFullEndElementAsync

適用於