Serializes and object to a stream. It will flush and close the underlying stream.
using System.IO;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
internal class Utility
{
public static void SerializeXml(Stream output, object data)
{
XmlSerializer xs = new XmlSerializer(data.GetType());
XmlWriterSettings settings = new XmlWriterSettings();
settings.Encoding = Encoding.UTF8;
XmlWriter writer = XmlTextWriter.Create(output, settings);
xs.Serialize(writer, data);
writer.Flush();
writer.Close();
}
}
Related examples in the same category