1.xml数据转化成对象(Config是xml转化成对象的类,xmlPath存放xml数据的路径/地址) xml数据反序列化成对象
XmlSerializer serializer = new XmlSerializer(typeof(Config));
StreamReader read = new StreamReader(xmlPath,Encoding.UTF8);
var config=_configInstance = serializer.Deserialize(read) as Config;
read.Close();
return config;
2. 对象转换成xml数据,对象序列化成xml数据(obj是数据对象,path是存储xml数据的地址/路径)
XmlSerializer serializer = new XmlSerializer(obj.GetType()); try { using (StreamWriter writer = new StreamWriter(path,false,Encoding.UTF8)) { serializer.Serialize(writer,obj); } } catch (Exception e) { throw e; } 3.
原文链接:https://www.f2er.com/xml/296479.html