In the dataset class, you can use the function GetXml() to return an XML output, but it’s not going to be formatted. The code below converts a dataset to formatted XML output. First, you need to add the IO namespace:
System.IO;
DataSet myDataSet;// DataSet to convert
//Use memory stearm to write your dataset onto it:
MemoryStream myMemoryStream = new MemoryStream();
myDataSet.WriteXml(myMemoryStream);
//Use StreamReader to read from the memory stream
StreamReader myStreamReader = new StreamReader(myMemoryStream, System.Text.Encoding.UTF8);
myMemoryStream.Position = 0; // start from position 0
String strOutput = myStreamReader.ReadToEnd(); // read to the end of the file
myStreamReader.Close(); // close stream reader
myMemoryStream.Close();// close momery stream