XElement xml = XElement.Parse(@"<DataSources>
<DataSource>
<Company>P</Company>
<UnitsFiles>
<UnitFile>
<Unit>Metric</Unit>
<File>rec_setup_P.dat</File>
</UnitFile>
<UnitFile>
<Unit>English</Unit>
<File>rec_setup_PEnglish.dat</File>
</UnitFile>
<UnitFile>
<Unit>Mexican</Unit>
<File>rec_setup_PMexico.dat</File>
</UnitFile>
</UnitsFiles>
</DataSource>
<DataSource>
<Company>I</Company>
<UnitsFiles>
<UnitFile>
<Unit>Metric</Unit>
<File>rec_setup_IMetric.dat</File>
</UnitFile>
<UnitFile>
<Unit>English</Unit>
<File>rec_setup_IEnglish.dat</File>
</UnitFile>
<UnitFile>
<Unit>Mexican</Unit>
<File>rec_setup_IMexico.dat</File>
</UnitFile>
</UnitsFiles>
</DataSource>
</DataSources>" );
// d'abord on isole les nodes
IEnumerable<XElement> allNodes = from node in xml.Nodes()
select node as XElement;
// puis on extrait les infos
var infos = (from element in allNodes
let company = ( from companies in element.Descendants()
where companies.Name == "Company"
select companies.Value)
let unit = ( from units in element.Descendants()
where units.Name == "Unit"
select units.Value)
let files = ( from files in element.Descendants()
where files.Name == "File"
select files.Value)
select new
{
c = company,
u = unit,
f = files
});
var infosArray = infos.ToArray();
foreach (var info in infosArray)
{
Console.WriteLine("Provider : {0}", info.c.ToArray()[0]);
Console.WriteLine("--------------" );
foreach (var unit in info.u.ToArray())
{
Console.WriteLine("Unit : {0}", unit);
}
foreach (var file in info.f.ToArray())
{
Console.WriteLine("File : {0}", file);
}
Console.WriteLine();
}