Copy codeThe Code is as follows:
Private string ConvertDataTableToXML (DataTable xmlDS)
{
MemoryStream stream = null;
XmlTextWriter writer = null;
Try
{
Stream = new MemoryStream ();
Writer = new XmlTextWriter (stream, Encoding. Default );
XmlDS. WriteXml (writer );
Int count = (int) stream. Length;
Byte [] arr = new byte [count];
Stream. Seek (0, SeekOrigin. Begin );
Stream. Read (arr, 0, count );
UTF8Encoding utf = new UTF8Encoding ();
Return utf. GetString (arr). Trim ();
}
Catch
{
Return String. Empty;
}
Finally
{
If (writer! = Null) writer. Close ();
}
}
Private DataSet ConvertXMLToDataSet (string xmlData)
{
StringReader stream = null;
XmlTextReader reader = null;
Try
{
DataSet xmlDS = new DataSet ();
Stream = new StringReader (xmlData );
Reader = new XmlTextReader (stream );
XmlDS. ReadXml (reader );
Return xmlDS;
}
Catch (Exception ex)
{
String strTest = ex. Message;
Return null;
}
Finally
{
If (reader! = Null)
Reader. Close ();
}
}