首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

linq to xml 的有关问题

2012-05-10 
linq to xml 的问题小弟对linq to xml还是菜鸟,望高手给予解答,现有这么一段xml代码,要把这里面的信息填充

linq to xml 的问题
小弟对linq to xml还是菜鸟,望高手给予解答,现有这么一段xml代码,要把这里面的信息填充到一个class societe中,对linq的语法不熟悉,写了半天没弄明白,xml中多余的项,不在类中的项可以不要

XML code
<?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>


C# code
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; }    }


[解决办法]
C# code
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; }    } 

热点排行