XmlTextWriter.Flush Metoda

Definicja

Opróżnia dowolny element w buforze do źródłowych strumieni, a także opróżnia bazowy strumień.

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

Przykłady

Poniższy przykład zapisuje dwa fragmenty XML.

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

Uwagi

Note

Zalecamy tworzenie XmlWriter wystąpień przy użyciu XmlWriter.Create metody i XmlWriterSettings klasy, aby korzystać z nowych funkcji.

Jest to wywoływane Close zamiast wtedy, gdy chcesz zapisać więcej do bazowego strumienia bez utraty tego, co jest nadal w buforze.

Dotyczy