首先创建一个类:将类 标记为可序列化 [XmlRoot("Root")]//类名为 文档的根节点 public class QQAccount { private string number; private string psword; private string lastLoginDate; private bool isStealth; private bool isChecked; [XmlElement(ElementName = "AcntNum")] public string Number { get { return number; } set { number = value; } } [XmlElement(ElementName = "AcntPsw")] public string Psword { get { return psword; } set { psword = value; } } [XmlElement(ElementName = "AcntLastLoginTime")] public string LastLoginDate { get { return lastLoginDate; } set { lastLoginDate = value; } } [XmlElement(ElementName = "AcntSts")] public bool IsStealth { get { return isStealth; } set { isStealth = value; } } [XmlElement(ElementName = "AcntChk")] public bool IsChecked { get { return isChecked; } set { isChecked = value; } } } 将类序列化 并写入xml文件: public static void SerializerXml(string path, List<QQAccount> qqList) { if (qqList == null) { throw new Exception("Parameter humanResource is Null"); } FileStream fs = null; try { //xmlSerializer 方法 序列化的对象typeof() XmlSerializer xs = new XmlSerializer(typeof(List<QQAccount>)); //FileStream将 fs = new FileStream(path,FileMode.Create,FileAccess.Write); xs.Serialize(fs, qqList);//Serialize()序列化方法(参数,(fs流对象),要序列化的对象) fs.Close(); } catch { if (fs != null) { fs.Close(); } throw new Exception("Xml serialzation failed"); } }