Dan Rigsby has the ultimate post on this – go read it!
XmlSerializer vs. DataContractSerializer (web archive)
He says all there is to say, and in a very convincing way.
In short:
XmlSerializer:
- has been around for a long time
- is “opt-out”; everything public gets serialized, unless you tell it not to ([XmlIgnore])
DataContractSerializer is:
- the new kid in town
- optimized for speed (about 10% faster than XmlSerializer, typically)
- “opt-in” – only stuff you specifically mark as
[DataMember]
will be serialized - but anything marked with
[DataMember]
will be serialized – whether it’spublic
orprivate
- doesn’t support XML attributes (for speed reasons)