[C#]将一个类序列化为XML

在C#中要想将一个类序列化为XML,则使用XmlSerializer类:

 

代码
   
   
XmlSerializer serializer = new XmlSerializer( typeof (PurchaseOrder));
TextWriter writer
= new StreamWriter(filename);
PurchaseOrder po
= new PurchaseOrder();
// Serialize the purchase order, and close the TextWriter.
serializer.Serialize(writer, po);
writer.Close();

 

可以参考WebService生成代理类的结构

你可能感兴趣的:(xml)