class XMLTransform
{
static void Main()
{
// Create the data source by using a collection initializer.
List
{
new Student {First="Svetlana", Last="Omelchenko", ID=111, Scores = new List
new Student {First="Claire", Last="O’Donnell", ID=112, Scores = new List
new Student {First="Sven", Last="Mortensen", ID=113, Scores = new List
};
// Create the query.
var studentsToXML = new XElement("Root",
from student in students
let x = String.Format("{0},{1},{2},{3}", student.Scores[0],
student.Scores[1], student.Scores[2], student.Scores[3])
select new XElement("student",
new XElement("First", student.First),
new XElement("Last", student.Last),
new XElement("Scores", x)
) // end "student"
); // end "Root"
// Execute the query.
Console.WriteLine(studentsToXML);
// Keep the console open in debug mode.
Console.WriteLine("Press any key to exit.");
Console.ReadKey();
}
}
The code produces the following XML output:
< Root>