Create XmlWriter using the static XmlWriter.Create method. : XML Write « XML « C# / C Sharp






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();
      }
   }
}

   
  








Related examples in the same category

1.Create XML document with XmlWriter
2.Read and Write XML Without Loading an Entire Document into MemoryRead and Write XML Without Loading an Entire Document into Memory
3.Writing XML with the XmlWriter ClassWriting XML with the XmlWriter Class
4.Write To XML File
5.Illustrates the XmlTextWriter class
6.Write XML document to console
7.XML Write: comment, start element, end element, attribute