XmlWriter.WriteEndElement Méthode

Définition

En cas de substitution dans une classe dérivée, ferme un élément et affiche l’étendue d’espace de noms correspondante.

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

Exceptions

Cela entraîne un document XML non valide.

- ou -

Une XmlWriter méthode a été appelée avant la fin d’une opération asynchrone précédente. Dans ce cas, InvalidOperationException est levée avec le message « Une opération asynchrone est déjà en cours ».

Exemples

L’exemple suivant utilise les WriteEndElement méthodes et les WriteFullEndElement méthodes.

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

Remarques

Si l’élément ne contient aucun contenu, une balise de fin abrégée « /> » est écrite ; sinon, une balise complète est écrite.

Note

Lorsque vous utilisez les méthodes pour générer du XmlWriter code XML, les éléments et attributs ne seront pas écrits tant que vous n’appelez pas la Close méthode. Par exemple, si vous utilisez xmlWriter pour remplir un XmlDocument, jusqu’à ce que vous fermez le XmlWriter, vous ne pourrez pas observer les éléments et attributs écrits dans le document cible.

Pour obtenir la version asynchrone de cette méthode, consultez WriteEndElementAsync.

S’applique à