Accepted answer

If you want something more strongly typed (than a dictionary of Strings), in terms of declared attribute names and types, you can create a DTO annotated with XmlSerizalizer attributes and use a generic array deserializer.

public class DtoI
    public int Id;
    public String Attribute1;
    public String Attribute2;
    public Int32 AttributeX;

public static T[] DeserializeArray<T>(String xml)
    using (var reader = new StringReader(xml))
        var serializer = new XmlSerializer(typeof(T[]), new XmlRootAttribute("root"));
        return (T[])serializer.Deserialize(reader);


I can do a Dictionary of attributes for each i tag in your Xml, and then return a collection of dictionaries.

IEnumerable<Dictionary<string, string>> result =
    from tag in response.Descendants("i")
    select tag.Attributes().Select(a =>
        new { key = a.Name.LocalName, value = a.Value.ToString() })
        .ToDictionary(k => k.key, v => v.value);

Related Articles