简体   繁体   中英

XML Serialization vs LINQ to XML

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

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM