An elegant way to write XML with Linq

While writing out some XML to a file I found a lot nicer way to write out XML while using Linq and the XStreamingElement.

The key is to use the XStreamingElement with data from a Linq datasource like so :

The above code will create the xml below (if the data is formatted correctly).:

As an added bonus this is a streaming class, so you have the added speed bonus of using a stream.

About the Author

Mike Griffith

Twitter Google+

A veteran programmer with over 20 years of experience in web development. If you have any questions please feel free to make a comment or send an email to

Mike GriffithAn elegant way to write XML with Linq