/// <summary> /// 将DataTable转换成xml /// </summary> /// <param name="dt"></param> /// <returns></returns> public static string DataTableToXml(DataTable dt) { StringBuilder sb = new StringBuilder(); XmlWriter writer = XmlWriter.Create(sb); XmlSerializer serializer = new XmlSerializer(typeof(DataTable)); serializer.Serialize(writer,dt); writer.Close(); return sb.ToString(); } /// <summary> /// 将xml转换成DataTable /// </summary> /// <param name="strXml"></param> /// <returns></returns> public static DataTable XmlToDataTable(string strXml) { StringReader strReader = new StringReader(strXml); XmlReader xmlReader = XmlReader.Create(strReader); XmlSerializer serializer = new XmlSerializer(typeof(DataTable)); DataTable dt = serializer.Deserialize(xmlReader) as DataTable; return dt; }