本文介绍了如何为以下XML构建我的类,以便可以将其反序列化为它们的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<data>
<notes>
<note>Note 1</note>
<note>Note 2</note>
</notes>
<conditions>
<condition>Condition 1</condition>
<condition>Condition 2</condition>
</conditions>
</data>
推荐答案
[Serializable]
[XmlRoot("data")]
public class MyData
{
[XmlArray(ElementName = "notes", Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
[XmlArrayItem(ElementName = "note", Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
public List<string> Notes { get; set; }
[XmlArray(ElementName="conditions", Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
[XmlArrayItem(ElementName = "condition", Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
public List<string> Conditions { get; set; }
}
这篇关于如何为以下XML构建我的类,以便可以将其反序列化为它们的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!