using System.Xml.Serialization;
public class XMLOperate
{
public static void SerialXml<T>(T t, string path)
{
using (FileStream finfo = new FileStream(path, FileMode.Create))
{
XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
ns.Add("", ""); //去除声明
XmlSerializer se = new XmlSerializer(typeof(T));
se.Serialize(finfo, t, ns);
}
}
public static T DeserialXml<T>(string path)
{
using (FileStream stream = new FileStream(path, FileMode.Open))
{
XmlSerializer se = new XmlSerializer(typeof(T));
return (T)se.Deserialize(stream);
}
}
}