XmlSerializer嵌套数组

时间:2019-04-19 00:41:21

标签: c# xml serialization xml-serialization xmlserializer

我需要获取XML的以下部分:

<TestInfo>
    //.....
    <Screenings>
       <UnitCodes>
          <UnitCode></UnitCode> <!-- Can be repeated -->
       </UnitCodes>
    </Screenings>
</TestInfo>

我有以下课程:

public class TestInfo
{
    //.... 
    [XmlArray("Screenings")]
    [XmlArrayItem("UnitCodes", typeof(Screening))]
    public List<Screening> Screenings { get; set; }
}

public class Screening
{
    [XmlArrayItem("UnitCode", typeof(string))]
    public List<string> UnitCodes { get; set; }
}

但它会生成:

<TestInfo>
    //.....
    <Screenings>
      <UnitCodes>
        <UnitCodes>
          <UnitCode>number</UnitCode>
        </UnitCodes>
      </UnitCodes>
    </Screenings>
</TestInfo>

如何删除不必要的(两次)UnitCodes节点?

谢谢!

0 个答案:

没有答案