XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; using (XmlWriter writer = XmlWriter.Create("example.xml", settings)) { writer.WriteStartDocument(); writer.WriteStartElement("root"); writer.WriteStartElement("element"); writer.WriteString("text"); writer.WriteEndElement(); writer.WriteEndElement(); writer.WriteEndDocument(); }
XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; using (XmlWriter writer = XmlWriter.Create("example.xml", settings)) { writer.WriteStartDocument(); writer.WriteStartElement("root"); writer.WriteStartElement("element"); writer.WriteAttributeString("attribute1", "value1"); writer.WriteAttributeString("attribute2", "value2"); writer.WriteString("text"); writer.WriteEndElement(); writer.WriteEndElement(); writer.WriteEndDocument(); }The C# XmlWriter class is part of the System.Xml namespace in the .NET Framework.