Partager via


XmlTextWriter.Flush Méthode

Définition

Vide le contenu de la mémoire tampon dans les flux sous-jacents, puis vide le flux sous-jacent.

public:
 override void Flush();
public override void Flush ();
override this.Flush : unit -> unit
Public Overrides Sub Flush ()

Exemples

L’exemple suivant écrit deux fragments XML.

#using <System.Xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{
   XmlTextWriter^ writer = gcnew 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();
}
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();
  }
}
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

Remarques

Notes

À compter de la .NET Framework 2.0, nous vous recommandons de créer XmlWriter des instances à l’aide de la XmlWriter.Create méthode et de la XmlWriterSettings classe pour tirer parti de nouvelles fonctionnalités.

Cela est appelé plutôt que Close lorsque vous souhaitez écrire davantage dans le flux sous-jacent sans perdre ce qui se trouve encore dans la mémoire tampon.

S’applique à