xml序列化与反序列化 - 整理文档

xml序列化与反序列化 - 整理文档

ID:6579380

大小:61.00 KB

页数:11页

时间:2018-01-18

xml序列化与反序列化 - 整理文档_第1页
xml序列化与反序列化 - 整理文档_第2页
xml序列化与反序列化 - 整理文档_第3页
xml序列化与反序列化 - 整理文档_第4页
xml序列化与反序列化 - 整理文档_第5页
资源描述:

《xml序列化与反序列化 - 整理文档》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库

1、XML序列化与反序列化整理文档XML序列化与反序列化   //OBJECT->XML   publicstaticvoidSaveXml(stringfilePath,objectobj){SaveXml(filePath,obj,obj.GetType());}   publicstaticvoidSaveXml(stringfilePath,objectobj,System.Typetype)   {       using(System.IO.StreamWriterwriter=newSystem.IO.

2、StreamWriter(filePath))       {           System.Xml.Serialization.XmlSerializerxs=newSystem.Xml.Serialization.XmlSerializer(type);           xs.Serialize(writer,obj);           writer.Close();       }   }   //XML->OBJECT   publicstaticobjectLoadXml(stringfil

3、ePath,System.Typetype)   {       if(!System.IO.File.Exists(filePath))           returnnull;       using(System.IO.StreamReaderreader=newSystem.IO.StreamReader(filePath))       {           System.Xml.Serialization.XmlSerializerxs=newSystem.Xml.Serialization.Xm

4、lSerializer(type);           objectobj=xs.Deserialize(reader);           reader.Close();           returnobj;       }   }相关的常用Attribute(命名空间System.Xml.Serialization)   [XmlRootAttribute("PurchaseOrder",Namespace="http://www.cpandl.com/",IsNullable=false)] //指

5、定根   [XmlIgnoreAttribute]                                                                     //跳过不序列化   [XmlArrayAttribute("Items")]publicOrderedItem[]OrderedItems;                          //层次序列化:..   [XmlEl

6、ementAttribute(ElementName="Link",IsNullable=false)]publicLink[]Links;         //平面序列化:...   [XmlAttribute("Cat")]publicstringCat;                                                 //表现为属性<...Cat=../>   [XmlElementAttribute(IsNullable=false

7、)]                                                  //表现为节点..相关的全部Attribute(命名空间System.Xml.Serialization)   XmlAttributes                    表示一个特性对象的集合,这些对象控制XmlSerializer如何序列化和反序列化对象。   XmlArrayAttribute                指定XmlSerializer应将特定的类成员序列化为

8、XML元素数组。   XmlArrayItemAttribute            指定XmlSerializer可以放置在序列化数组中的派生类型。   XmlArrayItemAttributes           表示XmlArrayItemAttribute对象的集合。   XmlAttributeAttribute            指定XmlSeria

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。