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.
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
)
)
)