次の方法で共有


XmlTextWriter.Flush メソッド

バッファ内のデータをすべて基になるストリームにフラッシュし、基になるストリームもフラッシュします。

Overrides Public Sub Flush()
[C#]
public override void Flush();
[C++]
public: void Flush();
[JScript]
public override function Flush();

解説

バッファ内のデータを消さずに、基になるストリームに追加の書き込みを行う場合は、 Close の代わりにこれが呼び出されます。

使用例

[Visual Basic, C#, C++] 2 つの XML フラグメントを書き込む例を次に示します。

 
Imports System
Imports System.IO
Imports System.Xml

public class Sample

  public shared sub Main()

     Dim writer as XmlTextWriter = new XmlTextWriter (Console.Out)
     'Use indenting for readability
     writer.Formatting = Formatting.Indented
    
     'Write an XML fragment.
     writer.WriteStartElement("book")
     writer.WriteElementString("title", "Pride And Prejudice")
     writer.WriteEndElement()
     writer.Flush()

     'Write another XML fragment.
     writer.WriteStartElement("cd")
     writer.WriteElementString("title", "Americana")
     writer.WriteEndElement()
     writer.Flush()  

     'Close the writer.
     writer.Close()

  end sub
end class

[C#] 
using System;
using System.IO;
using System.Xml;

public class Sample
{

  public static void Main()
  {
     XmlTextWriter writer = new XmlTextWriter (Console.Out);
     //Use indenting for readability
     writer.Formatting = Formatting.Indented;
    
     //Write an XML fragment.
     writer.WriteStartElement("book");
     writer.WriteElementString("title", "Pride And Prejudice");
     writer.WriteEndElement();
     writer.Flush();

     //Write another XML fragment.
     writer.WriteStartElement("cd");
     writer.WriteElementString("title", "Americana");
     writer.WriteEndElement();
     writer.Flush();  

     //Close the writer.
     writer.Close();
  }
}

[C++] 
#using <mscorlib.dll>
#using <System.Xml.dll>
using namespace System;
using namespace System::IO;
using namespace System::Xml;

int main() 
{
   XmlTextWriter* writer = new XmlTextWriter (Console::Out);
   // Use indenting for readability
   writer -> Formatting = Formatting::Indented;

   // Write an XML fragment.
   writer -> WriteStartElement(S"book");
   writer -> WriteElementString(S"title", S"Pride And Prejudice");
   writer -> WriteEndElement();
   writer -> Flush();

   // Write another XML fragment.
   writer -> WriteStartElement(S"cd");
   writer -> WriteElementString(S"title", S"Americana");
   writer -> WriteEndElement();
   writer -> Flush();  

   // Close the writer.
   writer -> Close();
}

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET, Common Language Infrastructure (CLI) Standard

参照

XmlTextWriter クラス | XmlTextWriter メンバ | System.Xml 名前空間