在将XML反序列化/序列化为C#对象时,我遇到了一个问题.XML struct 具有混合的元素顺序,我遇到了名称相同但用途不同的元素的问题.下面是我的C#类的简化版本:
public class Uientry
{
[XmlElement(ElementName = "u")]
public string ID { get; set; }
[XmlElement(ElementName = "s")]
public List<string> Strings { get; set; }
[XmlElement(ElementName = "i")]
public List<string> Integer { get; set; }
[XmlElement(ElementName = "additional_data")]
public Additional_data Additional_data { get; set; }
}
当XML具有具有相同名称但不同目的的元素时就会出现问题,and their order is not fixed. For example, the 100 elements (representing integers) can appear before and after 101 elements (representing strings), causing conflicts.
重要提示:我希望元素的顺序在序列化后保持不变
this is some of my xml code个
<uientry>
<u>606917248</u><!-- ID (80 d2 2c 24) -->
<s>root</s><!-- title -->
<s>CampaignRoot</s><!-- title2 -->
<i>0</i><!-- x offset -->
<i>0</i><!-- y offset -->
<no /><!-- uientry flag 1 -->
<yes /><!-- uientry flag 2 -->
<byte>1</byte><!-- uientry flag 3 -->
<no /><!-- uientry flag 4 -->
<no /><!-- uientry flag 5 -->
<no /><!-- uientry flag 6 -->
<no /><!-- uientry flag 7 -->
<yes /><!-- uientry flag 8 -->
<no /><!-- uientry flag 9 -->
<no /><!-- uientry flag 10 -->
<no /><!-- uientry flag 11 -->
<no /><!-- uientry flag 12 -->
<yes />
<unicode></unicode><!-- tooltip text -->
<unicode></unicode><!-- tooltip id -->
<i>0</i><!-- 00:00:00:00 --><!-- docking? -->
<i>0</i><!-- 00:00:00:00 --><!-- docking x? -->
<i>0</i><!-- 00:00:00:00 --><!-- docking y? -->
<no />
<i>0</i><!-- default state id -->
<images count="1">
<image>
<u>606535040</u><!-- ID (80 fd 26 24) -->
<s></s><!-- path -->
<i>1280</i><!-- x size -->
<i>960</i><!-- y size -->
<no />
</image>
</images>
<i>0</i><!-- 00:00:00:00 --><!-- mask image? -->
<i>0</i>
<states count="0">
</states>
<children count="0">
</children>
<additional_data type="none" />
</uientry>
我如何修改我的C#类或使用属性来处理这种情况?有没有办法指示XML反序列化程序考虑元素的用途并相应地处理它?