xml反序列化很方便,示例:
[XmlRoot(Root = "result")] public class UniMsgSetResult { [XmlAttribute("resultCode")] public int resultCode; [XmlElement("uniMsgSet")] public UniMsgSet uniMsgSet; }
登录后复制
...
登录后复制
集合类型示例:
[XmlRoot("result")] public class GetDiskInnerResult { public string parentCatalogID; //String32 待查询目录的父目录ID。如果当前目录为root,则父目录ID为空。 [XmlArray("catalogList"), XmlArrayItem("catalogInfo")] public List catalogList;// CatalogInfo[] 查询节点下的目录列表 [XmlArray("contentList"), XmlArrayItem("contentInfo")] public List contentList; // ContentInfo[] 查询节点下的内容列表 }
登录后复制
1 ... ... ... ...
登录后复制
如果要为集合实体添加属性:
In order words, add an attribute to an object element after xml serialization,
If you want something like,
little rat old rat
登录后复制
The C# code is
[XmlType(“Rats”)] public class Rats { [XmlAttribute(“count”)] public int Count { get; set; } [XmlElement(“Rat”)] // now the array element will be as same as the object element Rats. public string[] Rat { get; set; } }
登录后复制
Traditional xml array serialization would get the extra element for the array itself.
[XmlType(“Rats”)] public class Rats { [XmlAttribute(“count”)] public int Count { get; set; } [XmlArray(“Rats”)] [XmlArrayItem(“Rat”)] public string[] Rat { get; set; } }
登录后复制
little rat old rat
登录后复制
以上就是C# xml反序列化的代码示例详情介绍的内容,更多相关内容请关注PHP中文网(www.php.cn)!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至253000106@qq.com举报,一经查实,本站将立刻删除。
发布者:PHP中文网,转转请注明出处:https://www.chuangxiangniao.com/p/2445253.html