XmlTextWriter.Close Méthode
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Ferme ce flux et le flux sous-jacent.
public:
override void Close();
public override void Close ();
override this.Close : unit -> unit
Public Overrides Sub Close ()
Exemples
L’exemple suivant écrit un fragment XML.
#using <System.Xml.dll>
using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{
//Create a writer to write XML to the console.
XmlTextWriter^ writer = nullptr;
writer = gcnew XmlTextWriter( Console::Out );
//Use indentation for readability.
writer->Formatting = Formatting::Indented;
writer->Indentation = 4;
//Write an element (this one is the root).
writer->WriteStartElement( "book" );
//Write the title element.
writer->WriteStartElement( "title" );
writer->WriteString( "Pride And Prejudice" );
writer->WriteEndElement();
//Write the close tag for the root element.
writer->WriteEndElement();
//Write the XML to file and close the writer.
writer->Close();
}
using System;
using System.IO;
using System.Xml;
public class Sample
{
public static void Main()
{
//Create a writer to write XML to the console.
XmlTextWriter writer = null;
writer = new XmlTextWriter (Console.Out);
//Use indentation for readability.
writer.Formatting = Formatting.Indented;
writer.Indentation = 4;
//Write an element (this one is the root).
writer.WriteStartElement("book");
//Write the title element.
writer.WriteStartElement("title");
writer.WriteString("Pride And Prejudice");
writer.WriteEndElement();
//Write the close tag for the root element.
writer.WriteEndElement();
//Write the XML to file and close the writer.
writer.Close();
}
}
Option Explicit
Option Strict
Imports System.IO
Imports System.Xml
Public Class Sample
Public Shared Sub Main()
'Create a writer to write XML to the console.
Dim writer As XmlTextWriter = Nothing
writer = New XmlTextWriter(Console.Out)
'Use indentation for readability.
writer.Formatting = Formatting.Indented
writer.Indentation = 4
'Write an element (this one is the root).
writer.WriteStartElement("book")
'Write the title element.
writer.WriteStartElement("title")
writer.WriteString("Pride And Prejudice")
writer.WriteEndElement()
'Write the close tag for the root element.
writer.WriteEndElement()
'Write the XML to file and 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.
Tous les éléments ou attributs ouverts sont automatiquement fermés.
Cette méthode ne lève aucune exception.