Ler en inglés

Compartir por


XmlWriter.WriteEndElement Método

Definición

Cuando se invalida en una clase derivada, cierra un elemento y extrae el ámbito de espacio de nombres correspondiente.

C#
public abstract void WriteEndElement ();

Excepciones

Esto da como resultado un documento XML no válido.

o bien

Se llamó un método XmlWriter antes de que se termine una operación asincrónica anterior. En este caso, se genera InvalidOperationException con el mensaje “Ya hay una operación asincrónica en curso”.

Ejemplos

En el ejemplo siguiente se usan los WriteEndElement métodos y WriteFullEndElement .

C#
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();
  }
}

Comentarios

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

Nota

Cuando se usan los XmlWriter métodos para generar XML, los elementos y atributos no se escribirán hasta que se llame al Close método . Por ejemplo, si usa XmlWriter para rellenar un XmlDocument, hasta que cierre XmlWriter, no 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

Produto Versións
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0