第一,首先有一个要被序列化成xml的类
public class xmlobject
{
private string _username="hello";
public string username
get
return _username;
}
set
_username = value;
//序列化时.方法是没被序列化的.这里算白写了
protected string getsomething(string whosname)
return whosname;
第二:对象---->xml
//执行后:会生成一个pp.xml,当然这个文件名是自己取的
xmlobjectxo = new xmlobject();
streamwriter sw = new streamwriter(server.mappath("pp.xml"));
xmlserializer xs = new xmlserializer(typeof(xmlobject));
xs.serialize(sw, xo);
sw.close();
第三: xml---->对象
从第二部的pp.xml转成对象xo
streamreader reader = file.opentext(server.mappath("pp.xml"));
xmlserializer serializer = new xmlserializer(typeof(xmlobject));
xmlobjectxo= (xmlobject)serializer.deserialize(reader);
reader.close();
return xo;