以下课程:
public class CodelistFilters
{
[System.Xml.Serialization.XmlArray]
public List<CodelistFilterAndElement> AndGroup;
}
public class CodelistFilterAndElement
{
[System.Xml.Serialization.XmlArray]
public List<CodelistFilterOrElement> OrGroup;
[System.Xml.Serialization.XmlAttribute]
public string Relationship { get { return "And"; } }
}
public class CodelistFilterOrElement
{
[System.Xml.Serialization.XmlElement]
public List<CodelistFilter> CodelistFilters;
[System.Xml.Serialization.XmlAttribute]
public string Relationship { get { return "Or"; } }
}
public class CodelistFilter
{
[System.Xml.Serialization.XmlAttribute]
public string Name { get; set; }
[System.Xml.Serialization.XmlAttribute]
public string Value1 { get; set; }
[System.Xml.Serialization.XmlAttribute]
public string Value2 { get; set; }
}
被序列化为
<CodelistFilters xmlns:xsi="http://www.w3.org/2001/XMLSchema">
<AndGroup>
<CodelistFilterAndElement>
<OrGroup>
<CodelistFilterOrElement>
<CodelistFilters>
<CodelistFilter Name="Description" Value1="test" />
</CodelistFilters>
</CodelistFilterOrElement>
</OrGroup>
</CodelistFilterAndElement>
</AndGroup>
我有点理解。但是,我正在努力实现这一目标:
<CodelistFilters xmlns:xsi="http://www.w3.org/2001/XMLSchema">
<Group Relationship="And">
<Group Relationship="Or">
<CodelistFilters Name="Description" Value1="test" />
</Group>
</Group>
我应该如何构建我的C#类来实现这一目标?我已经尝试过使用XmlAttributes和嵌套列表,但最终会得到不同版本的&#34;错误&#34;。
答案 0 :(得分:2)