Compartir a través de


XmlTextWriter.Flush Método

Definición

Vuelca el contenido del búfer en los flujos subyacentes y también vuelca el flujo subyacente.

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

Ejemplos

En el ejemplo siguiente se escriben dos fragmentos 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

Comentarios

Nota

A partir de .NET Framework 2.0, se recomienda crear XmlWriter instancias mediante el XmlWriter.Create método y la XmlWriterSettings clase para aprovechar las nuevas funcionalidades.

Se llama a esto en lugar de Close cuando se desea escribir más en la secuencia subyacente sin perder lo que todavía está en el búfer.

Se aplica a