LINQ to XML

The previous sections of this chapter provided you with a general understanding of XML, how it is structured and how it can be accessed and manipulated using the .NET Framework. This section covers working with XML using newer features, specifically Language Integrated Query (LINQ), added in version 3.5 of the framework.

With the introduction of LINQ to the .NET Framework, the focus was on easy access to the data that you want to work with in your applications. One of the main data stores in the application space is XML, so it was really a no-brainer to create the LINQ to XML implementation. With the inclusion of System.Xml.Linq, you now have a series of capabilities that make the process of working with XML in your code much easier to achieve.

This chapter will only touch on how LINQ is used in relationship to XML. For the more basic description of LINQ and how it is used or works in a general sense, refer to chapter 9.

LINQ Helper XML Objects

Even if the LINQ querying capability were not around, the new objects available to work with the XML are so good that they can even stand on their own outside LINQ. Within the new System.Xml.Linq namespace, you will find a series of new LINQ to XML helper objects that make working with an XML document in memory that much easier. The following sections describe the new objects that are available within this new namespace.

Note
Many of the examples in this chapter use a file called Hamlet.xml, which you can find included in ...

Get Professional Visual Basic 2012 and .NET 4.5 Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.