using System.IO; using System.Xml; class Program { static void Main(string[] args) { // Create an XML writer XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; using (XmlWriter writer = XmlWriter.Create("output.xml", settings)) { // Write some XML writer.WriteStartElement("root"); writer.WriteStartElement("element"); writer.WriteString("Some text"); writer.WriteEndElement(); writer.WriteEndElement(); // Flush any buffered data to the output stream IaXmlWriter iaWriter = (IaXmlWriter)writer; iaWriter.Flush(); } } }
using System.IO; using System.Xml; class Program { static void Main(string[] args) { // Create an XML writer XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; using (TextWriter textWriter = new StreamWriter("output.xml")) using (XmlWriter writer = XmlWriter.Create(textWriter, settings)) { // Write some XML writer.WriteStartElement("root"); writer.WriteStartElement("element"); writer.WriteString("Some text"); writer.WriteEndElement(); writer.WriteEndElement(); // Flush any buffered data to the output stream IaXmlWriter iaWriter = (IaXmlWriter)writer; iaWriter.Flush(); } } }In this example, we create an XML writer that writes to a text writer, which is then used to write the XML to a file. We again cast the XML writer to an IaXmlWriter and call the Flush method to ensure that all output is written to the file. Package/Library: System.Xml.