Converting a XML to Generic List

后端 未结 3 596
無奈伤痛
無奈伤痛 2020-12-10 12:35

I am trying to convert XML to List


  
    2
    dummy
    
12
3条回答
  •  独厮守ぢ
    2020-12-10 13:19

    var students = from student in dox.Descendants("Student")
               select new
                {
                    id=d.Element("Id").Value,
                    Name=d.Element("Name").Value,
                    Section=d.Element("Section").Value
                }).ToList();
    

    or you can create a class call Student with id, name and section as properties and do:

    var students = from student in dox.Descendants("Student")
               select new Student
                {
                    id=d.Element("Id").Value,
                    Name=d.Element("Name").Value,
                    Section=d.Element("Section").Value
                }).ToList();
    

提交回复
热议问题