集合数据怎么转换为XML格式
1个回答
展开全部
给你个例子作为参考:
protected void Page_Load(object sender, EventArgs e)
{
List<Student> students = new List<Student>()
{
new Student { ID=1, Name="张三", Score=70},
new Student {ID=2, Name="李四", Score=80}
};
var studentXML = new XElement("Root",from student in students
select new XElement("student",
new XElement("ID",student.ID),
new XElement("Name",student.Name),
new XElement("Score", student.Score)));
Response.ContentType = "application/xml";
Response.Charset = "utf-8";
Response.Write(studentXML);
Response.End();
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询