linq to xml 的问题
小弟对linq to xml还是菜鸟,望高手给予解答,现有这么一段xml代码,要把这里面的信息填充到一个class societe中,对linq的语法不熟悉,写了半天没弄明白,xml中多余的项,不在类中的项可以不要
<?xml version="1.0" encoding="ISO-8859-1"?><!DOCTYPE main>-<main> <no type="siret">44373969300010</no> <deno>AXONES</deno> <enseigne/> <adresse>205 Avenue Georges Clemenceau - Immeuble le Clemenceau</adresse> <codepostal>92024</codepostal> <commune>NANTERRE CEDEX</commune> <ape>6201Z</ape> <apetexte>Programmation informatique</apetexte> <typeetab>siège</typeetab><url>http://www.societe.com/societe/axones-443739693.html</url> </main>
class Societe { public string nosiret { get; set; } public string deno { get; set; } public string adresse { get; set; } public string codepostal { get; set; } public string commune { get; set; } public string struri { get; set; } }void Main(){ XDocument data=XDocument.Load(@"c:\test.xml"); var query=from item in data.Descendants("main") select new Societe { deno=item.Element("no").Value, struri=item.Element("url").Value, //以下你懂的 }; Console.WriteLine(query);}class Societe { public string nosiret { get; set; } public string deno { get; set; } public string adresse { get; set; } public string codepostal { get; set; } public string commune { get; set; } public string struri { get; set; } }