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