using System; using System.Xml; class Program { static void Main(string[] args) { using (XmlWriter writer = XmlWriter.Create("output.xml")) { writer.WriteStartElement("root"); writer.WriteStartElement("person"); writer.WriteAttributeString("name", "John"); writer.WriteEndElement(); writer.WriteStartElement("person"); writer.WriteAttributeString("name", "Jane"); writer.WriteEndElement(); writer.WriteEndElement(); } Console.WriteLine("XML file written."); Console.ReadKey(); } }
The package library for XmlWriter is the System.Xml namespace, which is included in the .NET Framework class library.