XmlWriter.Close Método

Definición

Cuando se invalida en una clase derivada, cierra esta secuencia y la secuencia subyacente.

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

Excepciones

Se realiza una llamada para escribir más resultados después Close de llamar a o el resultado de esta llamada es un documento XML no válido.

O bien

Se llamó a un XmlWriter método antes de que finalice una operación asincrónica anterior. En este caso, InvalidOperationException se produce con el mensaje "Una operación asincrónica ya está en curso".

Ejemplos

En el ejemplo siguiente se escribe un nodo XML.

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.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
End Class

Comentarios

Los elementos o atributos abiertos a la izquierda se cierran automáticamente.

Note

Cuando se usan los XmlWriter métodos para generar XML, los elementos y atributos no se escribirán hasta que llame al Close método . Por ejemplo, si usa XmlWriter para rellenar un XmlDocument, hasta que cierre , XmlWriterno podrá observar los elementos y atributos escritos en el documento de destino.

Se aplica a