问题描述
我需要编写一个类来序列化以下XML:
Hi, I need to write a class to serialize the following XML:
<xml>
<body>
<Team type="request" selection="whatever">
<Test1>
</Test1>
<Test2>
</Test2>
</Team>
<Team type="input">
<Test3>
</Test3>
<Test4>
</Test4>
<Test5>
</Test5>
</Team>
</body>
</xml>
我是新手到XML序列化,这就是我将序列化的方式,例如顶级团队类:
[Serializable()]
[XmlRoot(ElementName =" Team")]
公共类团队
{
私人string _test1;
private test2 _test2;
[XmlElement(ElementName =" Test1")]
公共字符串Test1
{
get {return _test1; } set {_test1 = value; }
[XmlElement(ElementName =" Test2")]
公共string Test2
{
get {return _test2; } set {_test2 = value; }}}}}
公共类Test2
{{br / > private string _testing;
[XmlAttribute(AttributeName =" Testing")]
public string测试
{
get {return _testing; } set {_testing = value;有问题请告诉我是否有更好的方法,以及如何序列化具有不同包含标签的Team类取决于类型属性?
提前感谢,Dan
[XmlAttribute(AttributeName = "Testing")]
public string Testing
{
get { return _testing; }
set { _testing= value; }
}
}
Can somebody please tell me if there is a better way of doing this, and how to serialize the Team class which has different containing tags depending on the type attribute?
Thanks in advance, Dan
推荐答案
这篇关于序列化XML问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!