一、使用VS2013生成类
首先使用ctr+c拷贝要序列化的xml(这一步必须做)
二、使用vs生成类
1、 首先新建一个空的类(根据需要去设置类名)
2、
3、类已经被建出来了。
xml序列化瘀饭序列方法:
/// <summary> /// xml序列化和反序列化 /// </summary> public sealed class XmlSerializeHelper { /// <summary> /// xml反序列化 /// </summary> /// <typeparam name="T">实体类</typeparam> /// <param name="xmlOrPath">xml字符或者xml文件路径</param> /// <returns></returns> public static T XmlDeserialize<T>(string xmlOrPath) { using (FileStream file = new FileStream(xmlOrPath, FileMode.Open, FileAccess.Read)) { XmlSerializer serializer = new XmlSerializer(typeof(T)); T obj = (T)serializer.Deserialize(file); file.Close(); return obj; } } /// <summary> /// xml序列化 /// </summary> /// <typeparam name="T">实体类</typeparam> /// <param name="obj">带有参数的实体</param> /// <returns></returns> public static string XmlSerialize<T>(T obj) { using (StringWriter sw = new StringWriter()) { XmlSerializer serializer = new XmlSerializer(obj.GetType()); serializer.Serialize(sw, obj); sw.Close(); return sw.ToString(); } } }