Mega Code Archive

 
Categories / C# / XML
 

Create XmlWriter using the static XmlWriter Create method

using System; using System.Linq; using System.Xml; using System.Xml.Linq; using System.Collections; using System.Collections.Generic; public class MainClass{    public static void Main(){                    XmlWriterSettings settings = new XmlWriterSettings();       settings.Indent = true;       settings.IndentChars = ("    ");       using (XmlWriter writer = XmlWriter.Create("books.xml", settings))       {           // Write XML data.           writer.WriteStartElement("book");           writer.WriteElementString("price", "19.95");           writer.WriteEndElement();           writer.Flush();       }    } }