This code

```
XmlDataDocument xmlDataDocument = new XmlDataDocument(ds);

```

does not work for me, because the node names are derived from the columns' encoded ColumnName property and will look like "last\_x20\_name", for instance. This I cannot use in the resulting Excel spreadsheet. In order to treat the column names to make them something more friendly, I need to generate the XML myself.

I like LINQ to XML, and one of the responses to [this question](https://stackoverflow.com/questions/3034611/whats-so-bad-about-building-xml-with-string-concatenation/3034624#3034624) contained the following snippets:

```
XDocument doc = new XDocument(new XDeclaration("1.0","UTF-8","yes"), 
new XElement("products", from p in collection 
 select new XElement("product", 
     new XAttribute("guid", p.ProductId),  
     new XAttribute("title", p.Title), 
     new XAttribute("version", p.Version)))); 

```

The entire goal is to dynamically derive the column names from the dataset, so hardcoding them is not an option. Can this be done with Linq and without making the code much longer?