XmlTextWriter.Flush Method
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Flushes whatever is in the buffer to the underlying streams and also flushes the underlying stream.
public:
override void Flush();
public override void Flush ();
override this.Flush : unit -> unit
Public Overrides Sub Flush ()
The following example writes out two XML fragments.
#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
Note
Starting with the .NET Framework 2.0, we recommend that you create XmlWriter instances by using the XmlWriter.Create method and the XmlWriterSettings class to take advantage of new functionality.
This is called instead of Close when you want to write more to the underlying stream without losing what is still in the buffer.
Product | Versions |
---|---|
.NET | Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.0, 2.1 |
.NET feedback
.NET is an open source project. Select a link to provide feedback: