XmlTextWriter.Close メソッド
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
このストリームおよび基になるストリームを閉じます。
public:
override void Close();
public override void Close ();
override this.Close : unit -> unit
Public Overrides Sub Close ()
例
次の例では、XML フラグメントを書き込みます。
#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;
writer->Indentation = 4;
//Write an element (this one is the root).
writer->WriteStartElement( "book" );
//Write the title element.
writer->WriteStartElement( "title" );
writer->WriteString( "Pride And Prejudice" );
writer->WriteEndElement();
//Write the close tag for the root element.
writer->WriteEndElement();
//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;
writer.Indentation = 4;
//Write an element (this one is the root).
writer.WriteStartElement("book");
//Write the title element.
writer.WriteStartElement("title");
writer.WriteString("Pride And Prejudice");
writer.WriteEndElement();
//Write the close tag for the root element.
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 writer As XmlTextWriter = Nothing
writer = New XmlTextWriter(Console.Out)
'Use indentation for readability.
writer.Formatting = Formatting.Indented
writer.Indentation = 4
'Write an element (this one is the root).
writer.WriteStartElement("book")
'Write the title element.
writer.WriteStartElement("title")
writer.WriteString("Pride And Prejudice")
writer.WriteEndElement()
'Write the close tag for the root element.
writer.WriteEndElement()
'Write the XML to file and close the writer.
writer.Close()
End Sub
End Class
注釈
注意
.NET Framework 2.0 以降では、新しい機能を利用するために、メソッドとクラスをXmlWriter.CreateXmlWriterSettings使用してインスタンスを作成XmlWriterすることをお勧めします。
開いたままの要素または属性はすべて自動的に閉じられます。
このメソッドは例外をスローしません。