Let’s Web developer has to develop a page where the user submits a file containing the ISBN of all the books he/she needs information about. The user has to retrieve these books and create an XML file with the book title, author and price.

C# 8.0 and .NET Core 3.0 – Modern Cross-Platform Development: Build applications with C#, .NET Core, Entity Framework Core, ASP.NET Core, and ML.NET using Visual Studio Code, 4th Edition
ASP.NET Core 3 and Angular 9: Full stack web development with .NET Core 3.1 and Angular 9, 3rd Edition
C# in Depth, 4th Edition

Web developer can use a LINQ query to pass child elements and nest data, by exploiting a possibility to pass a list of elements to the XElement constructor. The following VB.NET code lines show this approach:

Dim books = BooksFromAQuery()
Dim book =
   New XDocument(
   New XElement(“Books”,
      From b In books
      Select New XElement(“Book”,
         New XElement(“ISBN”, b.ISBN),
         New XElement(“Title”, b.Title),
         New XElement(“Author”, b.Author),
         New XElement(“Price”, b.Price