Вот ваш класс операций
public class Operations
{
public string Name { get; set; }
public string Id { get; set; }
public string OperationDate { get; set; }
public string OperationDetails { get; set; }
public string OperationDesc { get; set; }
}
Теперь нам нужно List<Operations>
из XML.
Вот полный код с реализацией LINQ
namespace ConsoleApplication
{
class Program
{
public static string xml = @"
<result>
<OperationsRow>
<Name>John</Name>
<Id>XYV10572</Id>
<OperationDate>2020-04-14T13:25:41</OperationDate>
<OperationDetails>welcome to the world</OperationDetails>
<OperationDesc>ABCDEF</OperationDesc>
</OperationsRow>
<OperationsRow>
<Name>Kennedy</Name>
<Id>XYM54572</Id>
<OperationDate>2018-04-14T13:11:41</OperationDate>
<OperationDetails>welcome to Newyork</OperationDetails>
<OperationDesc>ZYX</OperationDesc>
</OperationsRow>
</result>";
static void Main(string[] args)
{
XDocument doc = XDocument.Parse(xml);
var operations =
from operation in doc.Descendants("result").Elements("OperationsRow")
select new Operations()
{
Id = operation.Element("Id").Value,
Name = operation.Element("Name").Value,
OperationDate = operation.Element("OperationDate").Value,
OperationDetails = operation.Element("OperationDetails").Value,
OperationDesc = operation.Element("OperationDesc").Value
};
}
}
Вы можете отслеживать структуру:
from operations in xml
.Element("result") // must be root
.Elements("OperationsRow") // only directly children of CompanyInfo
или менее строго
from employee in xml.Descendants("OperationsRow") // all employees at any level
И затем получить необходимую информацию:
select new Operations()
{
Id = operation.Element("Id").Value,
Name = operation.Element("Name").Value
//........
}
Надеюсь, это поможет ,