Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LinqToXml OR Xml?

I am trying to processing on xml and i am so tired to work with Xml namespace classes. I found it really hard.

So i am trying to do same things with LinqtoXml classes and i see that many things possible with LinqtoXml instead of Xml classes. So i really get confused which i have to use.

When and why do u prefer Xml classes instead of LinqtoXml classes ?

Edit:

What is not possible to do with LinqToXml when it is possible with Xml classes ?

like image 276
Freshblood Avatar asked Jul 10 '10 20:07

Freshblood


2 Answers

General methods used to manipulate and process XML data were available since the first version of .NET Framework. Linq is available since .NET Framework 3.5. That's one of the reasons to use plain Xml classes if you target an older version of .NET Framework.

Linq to Xml has also a different approach. It's more about querying XML data, and not reading it. So in some situations, Linq to Xml will be the easiest way to do things, but not in every situation. The ease of Linq to Xml may also be a bad thing if used by an unskilled developer: it is, IMHO, much easier to produce code with huge performance issues with Linq rather than without.

like image 169
Arseni Mourzenko Avatar answered Sep 30 '22 21:09

Arseni Mourzenko


Working exclusively in the LINQ to XML space is good for querying (the Q in LINQ), and projecting the original XML data into new structures, but it's unwieldy in some cases and impossible in others to manipulate the XML directly.

One can make an argument that in many cases this is still a good thing, since immutability does reduce the chance of some kinds of bugs, but it definitely can have costs - not perfectly aligning with every situation, and sometimes performance.

like image 22
Rex M Avatar answered Sep 30 '22 21:09

Rex M