first_page the funky knowledge base
personal notes from way, _way_ back and maybe today

LINQ to XML: Using System.Linq.Enumerable to Generate XML; Code from Mike Taulty, Microsoft UK

/* using System; using System.Linq; using System.Xml.Linq; */

var numbers =

from n in Enumerable.Range( 1, 20 )

let attributes =
    new Object[]{
        new XAttribute( "value", n ),
        new XAttribute( "squared", n * n ) }

select new XElement( "number", attributes );

XElement document = new XElement( "numbers", numbers );

Console.WriteLine( document.ToString() );

/*

This code is derived from Mike Taulty (Microsoft UK Ltd.) here:
http://mtaulty.com/downloads/MTLaunchLINQXML.zip

For more information, see
“LINQ Talk at UK Visual Studio 2008 Launch”
http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/
    archive/2008/03/20/10255.aspx

*/

mod date: 2008-03-23T03:09:19.000Z