XML Serialization in .NET provides an incredibly useful (and easy) way to turn objects into XML and back again. However, in some situations, you may need more control over how your object is serialized. Recently, I found myself needing to serialize an object that contained a number of property name/values – stored using a NameValueCollection. However, you can’t serialize this using the XmlSerializer class in .NET. I could have switched to using an array – at least for the serialization part – but this would have serialized the whole lot as a series of elements – and I wanted to do this using attributes.
[Apologies – I’ve had to snip the code from here, as the layout kept messing around]
Read more here: Customize XML Serialization using IXmlSerializable.