using System.Xml; using System.IO; XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; using (XmlWriter writer = XmlWriter.Create("example.xml", settings)) { writer.WriteStartElement("root"); writer.WriteStartElement("child"); writer.WriteString("Example text"); writer.WriteEndElement(); writer.WriteEndElement(); }
using System.Xml; XmlWriter writer = XmlWriter.Create(Console.Out); writer.WriteStartElement("book"); writer.WriteAttributeString("price", "19.99"); writer.WriteString("This is a book about C# programming."); writer.WriteEndElement(); writer.Flush();This example writes to the console an XML element 'book' with an attribute 'price' and a text node with the description of the book. In summary, WriteStartElement method is part of System.Xml.XmlWriter package library and is used to write element tags to an XML stream.