Search code examples
.netxmlxml-serializationlinq-to-xmldatacontractserializer

How do I choose between Xml serialization, DataContractSerializer and LINQ to XML for serializing a tree of simple objects?


I need to serialize a tree of simple objects as XML to/from a file – the world has changed since I last had to do this…

(I don’t care about the schema of the XML provided a support person can understand the file if needed)

So what are the trade off to consider when choosing between the different “easy xml” APIs in .net?


Solution

  • This is how I have come to think about the options:

    LINQ to XML – full control over the XML and the design of the objects, the most code of any of the 3 options.

    DataContractSerializer – little or no control over the XML, can cope with most objects

    XmlSerializer – full control over the XML, but you must design the objects in a way that Xml Serialization likes.