Deserialize xml which uses attribute name/value pairs
- by Bodyloss
My application receives a constant stream of xml files which are more or less a direct copy of the database record
<record type="update">
<field name="id">987654321</field>
<field name="user_id">4321</field>
<field name="updated">2011-11-24 13:43:23</field>
</record>
And I need to deserialize this into a class which provides nullable property's for all columns
class Record {
public long? Id { get; set; }
public long? UserId { get; set; }
public DateTime? Updated { get; set; }
}
I just cant seem to work out a method of doing this without having to parse the xml file manually and switch on the field's name attribute to store the values.
Is their a way this can be achieved quickly using an XmlSerializer? And if not is their a more efficient way of parsing it manually?
Regards and thanks
My main problem is that the attribute name needs to have its value set to a property name and its value as the contents of a <field>..</field> element