Creating XDocument using Data from Database
With Vb, building an XML Document on the fly from a list in the database is very simple. Vb supports the concept of embedded expressions which is similar to asp.net concept of embedding code expressions in aspx page. This allows you to build you XML file as it should look when its opened. XML literals also allows you to replace sections of the file with data from anything that is IEnumerable. Example below builds an XML document from a list in the database.
In the example above, I am creating an XDocument object from list of products in categoryId of 1 which you can see as my query is filtering the products to return only products in category of 1. Next I create 3 elements inside my Products element tag. Notice I am using the class asp.net syntax of putting code expressions inside of each of 3 elements. This results in getting us a well formed XML that has all the products in an XML format we desire. Output below confirms the result.