XmlTextWriter.WriteFullEndElement 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
關閉一個項目並快顯對應的命名空間範圍。
public:
override void WriteFullEndElement();
public override void WriteFullEndElement ();
override this.WriteFullEndElement : unit -> unit
Public Overrides Sub WriteFullEndElement ()
範例
下列範例會寫出沒有內容的專案。 它會使用 WriteFullEndElement 來寫入完整的結束專案標記。
#using <System.Xml.dll>
using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{
//Create a writer to write XML to the console.
XmlTextWriter^ writer = nullptr;
writer = gcnew XmlTextWriter( Console::Out );
//Use indentation for readability.
writer->Formatting = Formatting::Indented;
//Write an element (this one is the root).
writer->WriteStartElement( "order" );
//Write some attributes.
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();
//Write the XML to file and close the writer
writer->Close();
}
using System;
using System.IO;
using System.Xml;
public class Sample
{
public static void Main()
{
//Create a writer to write XML to the console.
XmlTextWriter writer = null;
writer = new XmlTextWriter (Console.Out);
//Use indentation for readability.
writer.Formatting = Formatting.Indented;
//Write an element (this one is the root).
writer.WriteStartElement("order");
//Write some attributes.
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();
//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 writer As XmlTextWriter = Nothing
writer = New XmlTextWriter(Console.Out)
'Use indentation for readability.
writer.Formatting = Formatting.Indented
'Write an element (this one is the root).
writer.WriteStartElement("order")
'Write some attributes.
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()
'Write the XML to file and close the writer
writer.Close()
End Sub
End Class
備註
注意
從 .NET Framework 2.0 開始,建議您使用 XmlWriter.Create 方法和 XmlWriterSettings 類別來建立 XmlWriter 實例,以利用新功能。
這個方法一律會寫入完整的結束標記。 這在處理必須包含完整結束標記的專案時很有用。 例如,瀏覽器預期 HTML 腳本區塊會以 「 < /script > 」 關閉。