XmlWriter.WriteEndElement Método

Definición

Cuando se reemplaza en una clase derivada, cierra un elemento y abre el ámbito del espacio de nombres correspondiente.

public:
 abstract void WriteEndElement();
public abstract void WriteEndElement();
abstract member WriteEndElement : unit -> unit
Public MustOverride Sub WriteEndElement ()

Excepciones

Esto da como resultado 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 usan los WriteEndElement métodos y WriteFullEndElement .

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;
     XmlWriter writer = XmlWriter.Create(Console.Out, settings);

     // Write the root element.
     writer.WriteStartElement("order");

     // Write an element with attributes.
     writer.WriteStartElement("item");
     writer.WriteAttributeString("date", "2/19/01");
     writer.WriteAttributeString("orderID", "136A5");

     // Write a full end element. Because this element has no
     // content, calling WriteEndElement would have written a
     // short end tag '/>'.
     writer.WriteFullEndElement();

     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 settings As XmlWriterSettings = new XmlWriterSettings()
     settings.Indent = true
     Dim writer As XmlWriter = XmlWriter.Create(Console.Out, settings)
        
     ' Write the root element.
     writer.WriteStartElement("order")
        
     ' Write an element with attributes.
     writer.WriteStartElement("item")
     writer.WriteAttributeString("date", "2/19/01")
     writer.WriteAttributeString("orderID", "136A5")
        
     ' Write a full end element. Because this element has no
     ' content, calling WriteEndElement would have written a
     ' short end tag '/>'.
     writer.WriteFullEndElement()
        
     writer.WriteEndElement()

     ' Write the XML to file and close the writer
     writer.Close()

    End Sub
End Class

Comentarios

Si el elemento no contiene contenido, se escribe una etiqueta "/>" de fin corto; de lo contrario, se escribe una etiqueta de extremo completo.

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.

Para obtener la versión asincrónica de este método, vea WriteEndElementAsync.

Se aplica a