来自类的XML序列化 [英] XML serialisation from classes

查看:83
本文介绍了来自类的XML序列化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的,


我需要生成一部分XML,如下所示:

。 ... 
<标签>
< Label1>< / Label1>
< Label2>< / Label2>
< Label3>< / Label3>
< Label4>< / Label4>
< Label5>< / Label5>
< Label6>< / Label6>
< / Labels>

基于此我可以创建一个classe名称Lable并在6个公共属性名称Label1中放置定义到Label6


但是可能会发生我以后需要更多的6个。


如何才能正确定义我的课程以便不限于标签数量? / p>

问候




解决方案

使用List< T>保存Label对象。您可以将Label对象添加到集合中并序列化List< T>。


>序列化/-的-XML序列化的例子

Dear all,

I need to generate part of an XML which is as below :

....
<Labels>
   <Label1></Label1>
   <Label2></Label2>
   <Label3></Label3>
   <Label4></Label4>
   <Label5></Label5>
   <Label6></Label6>
</Labels>

Based on that I could create a classe name Lable and place define inside 6 public property name Label1 to Label6

But it could happen that I would need more that 6 at later time.

how can I define correctly my class in order to not be limited to number of label ?

regards

解决方案

By using a List<T> to hold the Label objects . You can add Label object to the collection and serialize the List<T>.

https://docs.microsoft.com/en-us/dotnet/standard/serialization/examples-of-xml-serialization


这篇关于来自类的XML序列化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆