using System.Collections.Generic;
public static void Main()
var xml =@"<?xml version=""1.0"" encoding=""utf-8""?>
<CustomerID>VINET</CustomerID>
<EmployeeID>5</EmployeeID>
<OrderDate>1996-07-04T00:00:00</OrderDate>
<RequiredDate>1996-08-01T00:00:00</RequiredDate>
<ShippedDate>1996-07-16T00:00:00</ShippedDate>
<Freight>32.3800</Freight>
<ShipName>Vins et alcools Chevalier</ShipName>
<ShipAddress>59 rue de l'Abbaye</ShipAddress>
<ShipCity>Reims</ShipCity>
<ShipPostalCode>51100</ShipPostalCode>
<ShipCountry>France</ShipCountry>
var doc = XDocument.Parse(xml);
var result= doc.Descendants("orders");
var data = result.ToList();
var table =ConvertToDataTable(data);
foreach(DataRow row in table.Rows){
foreach(var col in row.ItemArray)
public static DataTable ConvertToDataTable(IEnumerable<XElement> data)
var table = new DataTable();
foreach(var xe in data.First().Descendants())
table.Columns.Add(xe.Name.LocalName,typeof(string));
foreach(var item in data)
var row = table.NewRow();
foreach(var xe in item.Descendants())
row[xe.Name.LocalName] = xe.Value;