How to deserialize into a List using the XmlSerializer

前端 未结 1 807
猫巷女王i
猫巷女王i 2020-12-31 00:18

I\'m trying to deserialize the XML below into class, with the Components deserialized into a List, but can\'t figure out how to do so

相关标签:
1条回答
  • 2020-12-31 01:20

    Add a property like this to hold the list of Components:

    [XmlArray()]
    public List<Component> Components { get; set; }
    

    Edit: Sorry I misread that. You want to read it into a collection of strings. I just tried this below and it worked on your sample. The key is just to setup the correct xml serialization attributes.

    public class ArsAction
    {
        [XmlArray]
        [XmlArrayItem(ElementName="Component")]
        public List<string> Components { get; set; }
    }
    
    0 讨论(0)
提交回复
热议问题