/// <summary> /// datatable转换xml /// </summary> /// <param name="xmlDS"></param> /// <returns></returns> public static string ConvertDataTableToXML(DataTable xmlDS) { StringBuilder strXml = new StringBuilder(); strXml.AppendLine("<MonitorData>"); for (int i = 0; i < xmlDS.Rows.Count; i++) { strXml.AppendLine("<" + xmlDS.TableName + ">"); for (int j = 0; j < xmlDS.Columns.Count; j++) { strXml.AppendLine("<" + xmlDS.Columns[j].ColumnName + ">" + xmlDS.Rows[i][j] + "</" + xmlDS.Columns[j].ColumnName + ">"); } strXml.AppendLine("</" + xmlDS.TableName + ">"); } strXml.AppendLine("</MonitorData>"); return strXml.ToString(); }