XmlTextWriter.Close Methode

Definition

Schließt diesen Datenstrom und den zugrunde liegenden Datenstrom.

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

Beispiele

Im folgenden Beispiel wird ein XML-Fragment geschrieben.

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

Hinweise

Note

Wir empfehlen Ihnen, XmlWriter Instanzen mithilfe der XmlWriter.Create Methode und der XmlWriterSettings Klasse zu erstellen, um von neuen Funktionen zu profitieren.

Alle elemente oder Attribute, die geöffnet bleiben, werden automatisch geschlossen.

Diese Methode löst keine Ausnahmen aus.

Gilt für: