Friday, October 12, 2012

Transforming Data Source objects into XML using LINQ

http://www.itorian.com/2012/09/transforming-data-source-objects-into_7545.html

var studentsToXML = new XElement("School",
from student in students
let x = String.Format("{0},{1},{2},{3}", student.Marks[0], student.Marks[1], student.Marks[2], student.Marks[3])
select new XElement("Student",
            new XElement("ID", student.ID),
            new XElement("Name", student.Name),
            new XElement("Address", student.Address),
            new XElement("Marks", x)
        ) //end of "student"
    ); //end of "Root

No comments:

Post a Comment