score:1

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.

[XmlType("i")]
public class DtoI
{
    [XmlAttribute("Object_ID")]
    public int Id;
    [XmlAttribute("attribute1")]
    public String Attribute1;
    [XmlAttribute("attribute2")]
    public String Attribute2;
    [XmlAttribute("attributex")]
    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);
    }
}

score:1

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