tags:

views:

579

answers:

2

Hi,

I have few questions on XML serialization and LINQ to XML.

When do we use XML Serialization and LINQ to XML? Please specify the kind of situations or scenarios to use XML Serialziation and LINQ to XML.

What are the differences between XML Serialization and LINQ to XML?

What are the benefits of using XML Serialziation over LINQ to XML and vice-versa.

I have read in msdn and various blogs about DOM vs LINQ to XML but could not find much information on XML Serialization vs LINQ to XML. It would be great if we can consolidate all the methods of XML in .NET with pros and cons.

Thanks for your help in advance.

Regards,

Sushma

+7  A: 

They are quite different things:

  • XML serialization allows you get the XML representation of a whole object, and to convert it back to an object. It is used when you need to store the current state of an object or to transfer it to a remote location.

  • LINQ to XML (or the XML classes of the .NET framework) is used to generate and process XML files that are obtained "as-is" and are not directly mapped to objects, such as data from RSS feeds.

Konamiman
+1  A: 

I totally agree with Konamiman answer. However you shouldn't also forget the fact that during the traversal, navigation if you will, process we usually deserialize the XML. This make the difference a bit subtle.

I would say LINQ to XML is primarily traversal strategy which could also be done for the purpose of deserialization.

yona