XmlSerializer - Deserialize different elements as collection of same element

前端 未结 2 790
北荒
北荒 2020-12-11 12:47

I have the following XML part which schema I can\'t change. NUMBER, REGION, MENTION, FEDERAL are columns:



        
2条回答
  •  无人及你
    2020-12-11 12:59

    You can use multiple XmlElements with one property:

    [XmlElement("NUMBER")]
    [XmlElement("REGION")]
    [XmlElement("MENTION")]
    [XmlElement("FEDERAL")]
    public List Columns {get;set;}
    

    It is even possible to specify different classes for different tag names:

    [XmlElement(ElementName = "One", Type = typeof(OneItem))]
    [XmlElement(ElementName = "Two", Type = typeof(TwoItem))]
    public List Items {get;set;}
    

提交回复
热议问题