How to deserialize xml using Linq?

后端 未结 3 1176
梦谈多话
梦谈多话 2020-12-06 13:18

How can i deserialize this xml using Linq? I want to create List


  
    1
    

        
3条回答
  •  北海茫月
    2020-12-06 14:04

    Showing the above answers in LINQ method syntax

    Descendants:

    var steps = xml.Descendants("Step").Select(step => new
    {
        Id = (int)step.Element("ID"),
        Name = step.Element("Name").Value,
        Description = step.Element("Description").Value
    });
    

    Elements:

    var steps2 = xml.Element("MySteps").Elements("Step").Select(step => new
    {
        Id = (int)step.Element("ID"),
        Name = step.Element("Name").Value,
        Description = step.Element("Description").Value
    });
    

提交回复
热议问题