xml序列化、反序列化
//xml序列化 public static string Seria(DataSet ds) { XmlSerializer serializer = new XmlSerializer(typeof(DataSet)); StringBuilder sb = new StringBuilder(); XmlWriter writer = XmlWriter.Create(sb); serializer.Serialize(writer, ds); return sb.ToString(); } //xml反序列化 public static DataSet DeSeria(string sb) { XmlSerializer serializer = new XmlSerializer(typeof(DataSet)); StringReader sr = new StringReader(sb); XmlReader xr = XmlReader.Create(sr); DataSet ds = (DataSet)serializer.Deserialize(xr); return ds; } public static string Seria<T>(T ds) { XmlSerializer serializer = new XmlSerializer(typeof(T)); StringBuilder sb = new StringBuilder(); XmlWriter writer = XmlWriter.Create(sb); serializer.Serialize(writer, ds); return sb.ToString(); } //xml反序列化 public static T DeSeria<T>(string sb) { XmlSerializer serializer = new XmlSerializer(typeof(T)); StringReader sr = new StringReader(sb); XmlReader xr = XmlReader.Create(sr); T ds = (T)serializer.Deserialize(xr); return ds; }