原文http://www.cnblogs.com/mgen/archive/2011/12/04/2276238.html

比如这样一个类,我们用XmlArrayItem特性标明数组内出现的元素类型:

publicclassa

{

[XmlArrayItem(Type =typeof(int)), XmlArrayItem(Type =typeof(Guid)), XmlArrayItem(Type =typeof(string))]

, "hehe", Guid.NewGuid() };

}

序列化的XML是:

<axmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xmlns:xsd="http://www.w3.org/2001/XMLSchema">

<arr>

</int>

<string>hehe</string>

<guid>291b7cba-fc32-4019-bb22-d5d61643b6a7</guid>

</arr>

</a>

字段arr的名称是以XML元素写入的。

但如果把XmlArrayItem都改成XmlElement特性:

publicclassa

{

[XmlElement(Type =typeof(int)), XmlElement(Type =typeof(Guid)), XmlElement(Type =typeof(string))]

, "hehe", Guid.NewGuid() };

}

序列化的XML是这样:

<axmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xmlns:xsd="http://www.w3.org/2001/XMLSchema">

</int>

<string>hehe</string>

<guid>5e7da5a0-d513-47b7-ae8f-80b404a9b0d4</guid>

</a>

并没有arr字段的名称!

注意你可以用XmlArrayItem或者XmlElement特性的ElementName来控制对应类型的XML元素名称。

最新文章

  1. 在VBA中新建工作簿
  2. 转行IT行业的心路历程3
  3. 报表开发工具中mysql数据库连接编码转化失效解决方案
  4. Cannot install ubuntu or other linux flavours on citrix Xen server
  5. Yii CDbCriteria
  6. 机器学习笔记1——Linear Regression with One Variable
  7. MYSQL 源代码 学习
  8. Android AlarmManager实现不间断轮询服务
  9. 腾讯測试project师笔试面试记录
  10. 程序猿学英语—In July the English learning summary
  11. 360浏览器和猎豹浏览器重定向后丢失get参数
  12. C#中文件下载的几种方法演示源码
  13. python day18 作业 Django 开发主机管理系统
  14. Spring_Four -- 团队项目设计完善&amp;编码测试
  15. shiro框架的UsernamePasswordToken与对应Realm中的AuthenticationToken的一点比较
  16. Confluence 6 嵌入的 H2 数据库
  17. .12-浅析webpack源码之NodeWatchFileSystem模块总览
  18. php循环删除文件夹和目录
  19. 使用 bibtex4word 实现在 office word 中管理并插入参考文献
  20. Nunjucks:Mozilla 开发的 JavaScript 模板引擎

热门文章

  1. 怎样在超级终端和PC之间通过串口传输文件
  2. EasyUI特殊情况下的BUG整理
  3. 移动web开发
  4. Android API在不同版本系统上的兼容性
  5. spoj COT2 - Count on a tree II 树上莫队
  6. Html 笔记1
  7. MVC4,MVC3,VS2012+ entity framework Migration from Sqlserver to Mysql
  8. VMware ESXI4.1 常用命令
  9. lint使用简介
  10. kafka学习(一)-背景及架构设计