通过C中的XmlSerializer类反序列化具有相同名称的多个XML元素#

我在表单中有一个XML

<备份时间表>
<攻击性模块>0&lt/攻击性模块>
<ScheduleType>0&lt/ScheduleType>
<时间表>0&lt/时间表>
<时间表>1&lt/时间表>
<时间表>0&lt/时间表>
<时间表>0&lt/时间表>
<时间表>0&lt/时间表>
<时间表>0&lt/时间表>
<时间表>0&lt/时间表>
<WindowsStart>480&lt/WindowsStart>
<WindowEnd>1020&lt/WindowEnd>
<计划间隔>0&lt/计划间隔>
&lt/备份时间表>

我需要对其进行反序列化,更改其内容,然后将其保存回去。我在阅读ScheduledDay元素时遇到了问题。
我的课就像

公共类备份计划设置
{
公共备份计划设置()
{
ScheduledDay=新整数[7];
}
…..
public int[]ScheduledDay{get;set;}
…..
}

现在,当我加载具有ScheduledDay的正确值的XML内容时,我的类数组仍然为NULL

我不能修改XML的内容/格式,因为它是遗留代码。我不想使用XDocument读取该值,因为它是一个大型XML,我需要再次序列化它

我在没有任何帮助的情况下搜索了很多。任何想法都将受到高度赞赏

谢谢

您不需要XmlArrayItem。您希望在不使用父元素的情况下序列化int数组,这意味着您应该使用xmlement装饰数组本身。因为您有一个特定的顺序,所以需要在XmlElement属性上使用order值。下面是相应修改的类:

公共类备份计划设置
{
公共备份计划设置()
{
ScheduledDay=新整数[7];
}
[XmlElement(顺序=1)]
公共int攻击模式;
[XmlElement(顺序=2)]
公共int调度类型;
//[XmlArrayItem(“ArrayRapper”)]
[XmlElement(顺序=3)]
public int[]ScheduledDay{get;set;}
[XmlElement(顺序=4)]
公共int窗口启动;
[XmlElement(顺序=5)]
公共int WindowEnd;
[XmlElement(顺序=6)]
公共int调度间隔;
}

以下是生成的xML:

<备份计划设置>
<攻击性模块>0&lt/攻击性模块>
<ScheduleType>0&lt/ScheduleType>
<时间表>0&lt/时间表>
<时间表>0&lt/时间表>
<时间表>0&lt/时间表>
<时间表>0&lt/时间表>
<时间表>0&lt/时间表>
<时间表>0&lt/时间表>
<时间表>0&lt/时间表>
<WindowsStart>0&lt/WindowsStart>
<WindowEnd>0&lt/WindowEnd>
<计划间隔>0&lt/计划间隔>
&lt/备份计划设置>

发表评论