Namespaces
using System.Data;
using System.IO;
using System.Xml.Serialization;
using System.Text;
Code
DataSet ds = new DataSet();
ds.Tables.Add();
ds.Tables[0].Columns.AddRange(new DataColumn[3] { new DataColumn("Id", typeof(int)),
new DataColumn("Name", typeof(string)),
new DataColumn("Country",typeof(string)) });
ds.Tables[0].Rows.Add(1, "John Hammond", "United States");
ds.Tables[0].Rows.Add(2, "Mudassar Khan", "India");
ds.Tables[0].Rows.Add(3, "Suzanne Mathews", "France");
ds.Tables[0].Rows.Add(4, "Robert Schidner", "Russia");
using (MemoryStream memoryStream = new MemoryStream())
{
using (TextWriter streamWriter = new StreamWriter(memoryStream))
{
XmlSerializer xmlSerializer = new XmlSerializer(typeof(DataSet));
xmlSerializer.Serialize(streamWriter, ds);
string xml = Encoding.UTF8.GetString(memoryStream.ToArray());
}
}