XmlTextWriter.Flush Metoda

Definice

Vyprázdní všechno, co je ve vyrovnávací paměti, do podkladových datových proudů a také vyprázdní podkladový datový proud.

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

Příklady

Následující příklad zapíše dva fragmenty 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

Poznámky

Poznámka

Počínaje verzí .NET Framework 2.0 doporučujeme vytvářet XmlWriter instance pomocí XmlWriter.Create metody a XmlWriterSettings třídy, abyste mohli využívat nové funkce.

Volá se místo Close toho, když chcete do podkladového datového proudu napsat více, aniž byste ztratili to, co je stále ve vyrovnávací paměti.

Platí pro