using System.Xml; class Program { static void Main(string[] args) { XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; using (XmlWriter writer = XmlWriter.Create("output.xml", settings)) { writer.WriteStartElement("root"); writer.WriteStartElement("child"); writer.WriteString("data"); writer.WriteEndElement(); // close "child" element writer.WriteEndElement(); // close "root" element } } }
In this example, the XmlDictionaryWriter.WriteEndElement method is called twice to close the "child" and "root" elements. Package library: System.Xml.data