Chapter 11. Common LINQ to XML scenarios

 

This chapter covers:

  • Building objects from XML
  • Creating XML from objects
  • Creating XML from data in a database
  • Creating XML from a CSV file

Now that we’ve learned about the LINQ to XML API and seen how to query and transform XML using LINQ to XML, it’s time to explore some common scenarios that you may come across when working with LINQ to XML. These include building objects from XML, creating XML from a set of objects, creating XML with data from a database, filtering and mixing data from a database with XML data, updating a database with data read from an XML file, and transforming text files into XML using LINQ to XML. As we explore these common scenarios, you’ll witness the powerful capabilities offered by LINQ to XML.

In addition to using LINQ to XML, we’ll also make extensive use of the capabilities offered by LINQ to Objects and LINQ to SQL in this chapter. At times, you might forget that we’re even talking about LINQ to XML because of the strong focus on LINQ to Objects and LINQ to SQL. Our ability to intertwine discussions of LINQ to XML along with LINQ to Objects and LINQ to SQL shows how well the LINQ technologies work together and how important it is to understand each one. In the end, our goal is to help you understand LINQ to XML and how it can be used to solve the common scenarios we’ve outlined, so we’ll try to stay on course.

11.1. Building objects from XML

11.2. Creating XML from object graphs

11.3. Creating XML with data from a database

11.4. Filtering and mixing data from a database with XML data

11.5. Reading XML and updating a database

11.6. Transforming text files into XML

11.7. Summary