Q:

Deserialize XML Node into a collection getting values from attributes

if i have some xml like this
        <SiteSettings>              
            <sortOptions>
                <add name="By Date" value="date" />
                <add name="By Rating" value="rating" />
            </sortOptions>
        </SiteSettings>

I'd like to deserialise this into an object like this
[XmlRoot("SiteSettings")]
public class SerializableSiteSettings
{
    public List<NameValuePair> SortOptions { get; set; }
}

public class NameValuePair
{
    [XmlAttribute("name")]
    public string Name { get; set; }
    [XmlAttribute("value")]
    public object Value { get; set; }
}

I tried adding this to the SortOptions but it did not work
    [XmlArrayItem("actionButtons", typeof(List<NameValuePair>))]
    public List<NameValuePair> ActionButtons { get; set; }

A:

There are a few issues with your use of XmlSerializer:

XmlSerializer needs to know the types to expect when (de)serializing.  When you have a field like public object Value { get; set; } it has no idea how to deserialize the field or what to expect therein.  You need to tell it that information -- but since Value is an attribute that suggests the field is something simple, like a string.  So, I'm going to assume in this answer that a string is sufficient to hold this information.
You need to tell XmlSerializer that your property named SortOptions is to be serialized with the name sortOptions, not SortOptions, using the XmlArray attribute.
You need to tell XmlSerializer that add is the name of each array element, using the XmlArrayItem attribute.

Thus, the following works and reads Value into a string:
[XmlRoot("SiteSettings")]
public class SerializableSiteSettings
{
    [XmlArray("sortOptions")]
    [XmlArrayItem("add", typeof(NameValuePair))]
    public List<NameValuePair> SortOptions { get; set; }
}

public class NameValuePair
{
    [XmlAttribute("name")]
    public string Name { get; set; }
    [XmlAttribute("value")]
    public string Value { get; set; }
}

If Value is not a string and is really is some polymorphic type, you may need to implement IXmlSerializable for NameValuePair, along the lines of the following: .NET XmlSerializer: polymorphic mapping based on attribute value.

