C#: Converting a Datatable to XML
Given a .Net datatable filled with data and an explicitly defined name and columns, we can extract it's XML in the following manner. public static XmlDocument ConvertToXML(DataTable dt) { string sXML; using (StringWriter sw = new StringWriter()) { dt.WriteXml(sw); sXML = sw.ToString(); } //Althought the following code is also working fine //MemoryStream mstr = new MemoryStream(); //dt.WriteXml(mstr, true); //mstr.Seek(0, SeekOrigin.Begin); ...