XmlWriter.Close XmlWriter.Close XmlWriter.Close XmlWriter.Close Method

Definition

Schließt beim Überschreiben in einer abgeleiteten Klasse diesen Stream und den zugrunde liegenden Stream. When overridden in a derived class, closes this stream and the underlying stream.

public:
 virtual void Close();
public virtual void Close ();
abstract member Close : unit -> unit
override this.Close : unit -> unit
Public Overridable Sub Close ()

Ausnahmen

Eine XmlWriter-Methode wurde aufgerufen, bevor ein vorheriger asynchroner Vorgang abgeschlossen wurde. An XmlWriter method was called before a previous asynchronous operation finished. In diesem Fall wird InvalidOperationException mit der Meldung „Es wird bereits ein asynchroner Vorgang ausgeführt“ ausgelöst. In this case, InvalidOperationException is thrown with the message "An asynchronous operation is already in progress."

Beispiele

Im folgende Beispiel schreibt einen XML-Knoten.The following example writes an XML node.

#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.
   XmlWriterSettings^ settings = gcnew XmlWriterSettings;
   settings->Indent = true;
   settings->OmitXmlDeclaration = true;
   XmlWriter^ writer = XmlWriter::Create( Console::Out, settings );
   
   // Write the book element.
   writer->WriteStartElement( L"book" );
   
   // Write the title element.
   writer->WriteStartElement( L"title" );
   writer->WriteString( L"Pride And Prejudice" );
   writer->WriteEndElement();
   
   // Write the close tag for the root element.
   writer->WriteEndElement();
   
   // Write the XML and close the writer.
   writer->Close();
   return 1;
}

using System;
using System.IO;
using System.Xml;

public class Sample {
  
  public static void Main() {
  
     // Create a writer to write XML to the console.
     XmlWriterSettings settings = new XmlWriterSettings();
     settings.Indent = true;
     settings.OmitXmlDeclaration = true;
     XmlWriter writer = XmlWriter.Create(Console.Out, settings);

     // Write the book element.
     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 and close the writer.
     writer.Close();  

  }
}
Option Explicit
Option Strict

Imports System
Imports System.IO
Imports System.Xml

Public Class Sample
    
  Public Shared Sub Main()

     ' Create a writer to write XML to the console.
     Dim settings As XmlWriterSettings = new XmlWriterSettings()
     settings.Indent = true
     settings.OmitXmlDeclaration = true
     Dim writer As XmlWriter = XmlWriter.Create(Console.Out, settings)

     ' Write the book element.
     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 and close the writer.
     writer.Close()

  End Sub 'Main 
End Class 'Sample

Hinweise

Alle Elemente oder Attribute, die offen gelassen werden automatisch geschlossen.Any elements or attributes left open are automatically closed.

Hinweis

Bei Verwendung der XmlWriter Methoden, um die Ausgabe der XML-Elemente und Attribute werden nicht geschrieben werden, bis zum Aufruf der Close Methode.When you use the XmlWriter methods to output XML, the elements and attributes will not be written until you call the Close method. Z. B., wenn Sie zum Auffüllen der "XmlWriter" Verwenden einer XmlDocument, bis Sie schließen die XmlWriter, die geschriebenen Elemente und Attribute im Zieldokument feststellen kann, wird nicht ausgeführt werden.For example, if you are using the XmlWriter to populate an XmlDocument, until you close the XmlWriter, you will not be able to observe the written elements and attributes in the target document.

Gilt für: