XML序列化可以让你使用class-friendly的方式操作XML。我们可以方便的将某个类序列化成XML字符串或文件,这里是一个例子。
Address类:
![None.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/None.gif)
![None.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/None.gif)
![ExpandedBlockStart.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/ExpandedBlockStart.gif)
![ContractedBlock.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/ContractedBlock.gif)
![dot.gif](https://www.cnblogs.com/Images/dot.gif)
![ExpandedSubBlockStart.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/ContractedSubBlock.gif)
![dot.gif](https://www.cnblogs.com/Images/dot.gif)
![InBlock.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/InBlock.gif)
![ExpandedSubBlockStart.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/ContractedSubBlock.gif)
![dot.gif](https://www.cnblogs.com/Images/dot.gif)
![ExpandedSubBlockStart.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/ContractedSubBlock.gif)
![dot.gif](https://www.cnblogs.com/Images/dot.gif)
![ExpandedSubBlockStart.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/ContractedSubBlock.gif)
![dot.gif](https://www.cnblogs.com/Images/dot.gif)
![ExpandedSubBlockEnd.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![InBlock.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/InBlock.gif)
![ExpandedSubBlockStart.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/ContractedSubBlock.gif)
![dot.gif](https://www.cnblogs.com/Images/dot.gif)
![ExpandedSubBlockStart.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/ContractedSubBlock.gif)
![dot.gif](https://www.cnblogs.com/Images/dot.gif)
![ExpandedSubBlockStart.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/ContractedSubBlock.gif)
![dot.gif](https://www.cnblogs.com/Images/dot.gif)
![ExpandedSubBlockEnd.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![InBlock.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/InBlock.gif)
![ExpandedSubBlockStart.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/ContractedSubBlock.gif)
![dot.gif](https://www.cnblogs.com/Images/dot.gif)
![ExpandedSubBlockStart.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/ContractedSubBlock.gif)
![dot.gif](https://www.cnblogs.com/Images/dot.gif)
![ExpandedSubBlockStart.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/ContractedSubBlock.gif)
![dot.gif](https://www.cnblogs.com/Images/dot.gif)
![ExpandedSubBlockEnd.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![ExpandedBlockEnd.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/ExpandedBlockEnd.gif)
Customer类:
![None.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/None.gif)
![None.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/None.gif)
![ExpandedBlockStart.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/ExpandedBlockStart.gif)
![ContractedBlock.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/ContractedBlock.gif)
![dot.gif](https://www.cnblogs.com/Images/dot.gif)
![ExpandedSubBlockStart.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/ContractedSubBlock.gif)
![dot.gif](https://www.cnblogs.com/Images/dot.gif)
![InBlock.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/InBlock.gif)
![ExpandedSubBlockStart.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/ContractedSubBlock.gif)
![dot.gif](https://www.cnblogs.com/Images/dot.gif)
![ExpandedSubBlockStart.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/ContractedSubBlock.gif)
![dot.gif](https://www.cnblogs.com/Images/dot.gif)
![ExpandedSubBlockStart.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/ContractedSubBlock.gif)
![dot.gif](https://www.cnblogs.com/Images/dot.gif)
![ExpandedSubBlockEnd.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![InBlock.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/InBlock.gif)
![ExpandedSubBlockStart.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/ContractedSubBlock.gif)
![dot.gif](https://www.cnblogs.com/Images/dot.gif)
![ExpandedSubBlockStart.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/ContractedSubBlock.gif)
![dot.gif](https://www.cnblogs.com/Images/dot.gif)
![ExpandedSubBlockStart.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/ContractedSubBlock.gif)
![dot.gif](https://www.cnblogs.com/Images/dot.gif)
![ExpandedSubBlockEnd.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![ExpandedBlockEnd.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/ExpandedBlockEnd.gif)
必须在将要序列化的类上加入特性[Serializable]
生成测试数据:
![None.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/None.gif)
![ExpandedBlockStart.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/ExpandedBlockStart.gif)
![ContractedBlock.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/ContractedBlock.gif)
![dot.gif](https://www.cnblogs.com/Images/dot.gif)
![InBlock.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/InBlock.gif)
![ExpandedBlockEnd.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/ExpandedBlockEnd.gif)
进行序列化操作。
![None.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/None.gif)
![None.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/None.gif)
![ExpandedBlockStart.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/ExpandedBlockStart.gif)
![ContractedBlock.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/ContractedBlock.gif)
![dot.gif](https://www.cnblogs.com/Images/dot.gif)
![InBlock.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/InBlock.gif)
![ExpandedBlockEnd.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![None.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/None.gif)
![None.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/None.gif)
![ExpandedBlockStart.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/ExpandedBlockStart.gif)
![ContractedBlock.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/ContractedBlock.gif)
![dot.gif](https://www.cnblogs.com/Images/dot.gif)
![InBlock.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/InBlock.gif)
![ExpandedBlockEnd.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![None.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/None.gif)
![None.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/None.gif)
![ExpandedBlockStart.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/ExpandedBlockStart.gif)
![ContractedBlock.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/ContractedBlock.gif)
![dot.gif](https://www.cnblogs.com/Images/dot.gif)
![InBlock.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/InBlock.gif)
![ExpandedSubBlockStart.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/ContractedSubBlock.gif)
![dot.gif](https://www.cnblogs.com/Images/dot.gif)
![InBlock.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/InBlock.gif)
![ExpandedSubBlockEnd.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![ExpandedBlockEnd.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![None.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/None.gif)
![None.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/None.gif)
![ExpandedBlockStart.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/ExpandedBlockStart.gif)
![ContractedBlock.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/ContractedBlock.gif)
![dot.gif](https://www.cnblogs.com/Images/dot.gif)
![InBlock.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/InBlock.gif)
![ExpandedSubBlockStart.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/ContractedSubBlock.gif)
![dot.gif](https://www.cnblogs.com/Images/dot.gif)
![InBlock.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/InBlock.gif)
![ExpandedSubBlockStart.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/ContractedSubBlock.gif)
![dot.gif](https://www.cnblogs.com/Images/dot.gif)
![InBlock.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/InBlock.gif)
![ExpandedSubBlockEnd.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![ExpandedSubBlockEnd.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![InBlock.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/InBlock.gif)
![ExpandedBlockEnd.gif](http://www.cnblogs.cc2/Images/OutliningIndicators/ExpandedBlockEnd.gif)
以上是序列化指定的类,及读取序列化后的XML内容的几种方式。
XML序列化可以让你使用class-friendly的方式操作XML。我们可以方便的将某个类序列化成XML字符串或文件,这里是一个例子。
Address类:
Customer类:
必须在将要序列化的类上加入特性[Serializable]
生成测试数据:
进行序列化操作。
以上是序列化指定的类,及读取序列化后的XML内容的几种方式。
转载于:https://www.cnblogs.com/zhdonghu/archive/2011/01/15/1936430.html