Write XML To Stream - CSharp System.Xml

CSharp examples for System.Xml:XML File

Description

Write XML To Stream

Demo Code


using System.Xml.Serialization;
using System.Xml;
using System.Text;
using System.IO;// w w w. j  a va  2  s.c  om
using System;

public class Main{
        public static void WriteToStream(Stream stream, object item){
         XmlTextWriter xmlTextWriter = new XmlTextWriter(stream, Encoding.UTF8)
         {Formatting = Formatting.Indented, Indentation = 3};
         XmlSerializer xs = new XmlSerializer(item.GetType());
         xs.Serialize(xmlTextWriter, item);
         xmlTextWriter.Flush();
         xmlTextWriter.Close();
      }
}

Related Tutorials