A lot of developers over the past few months have requested us for tutorials focusing on LINQTo XML.
Although I have written a couple of them in the past, I decided to republish these tips in the form of a single post.
Both the classes contain the ‘Load()’ method which accepts a file, a URL or XMLReader and allows XML to be loaded.
The primary difference between both the classes is that an XDocument can contain XML declaration, XML Document Type (DTD) and processing instructions. All the manipulations we have done so far were in the memory and were not persisted in the XML file. It’s also worth observing that the structure of the code shown below is similar to the structure of the end result (XML document).
This enables many scenarios that require flexibility in how data is represented and handled, such as querying locally aggregated data and middle-tier caching in Web applications.