首页 新闻 会员 周边

Linq To SQL 解决个问题

0
悬赏园豆:50 [已解决问题] 解决于 2010-07-27 10:03

<Error>
 <ErrorType type="DataBase">
  <ErrorItem>
   <code>0</code>
   <type>fail</type>
   <text>添加错误</text>
   <des></des>
  </ErrorItem>
  <ErrorItem>
   <code>1</code>
   <type>success</type>
   <text>执行成功</text>
   <des>简要说明,一般不显示</des>
   
  </ErrorItem>
  <ErrorItem>
   <code>3</code>
   <type>fail</type>
   <text>数据重复</text>
   <des>重复数据</des>
  </ErrorItem>
 </ErrorType>
 
 <ErrorType type="Program">
  <ErrorItem></ErrorItem>
 </ErrorType>
 
 <ErrorType type="Install">
  <ErrorItem>
   
  </ErrorItem>
 </ErrorType>
</Error>

 

要获取 code 为1的 ErrorItem

老衲在厦门的主页 老衲在厦门 | 初学一级 | 园豆:150
提问于:2010-07-26 15:09
< >
分享
最佳答案
0

不是linq to sql吧,应该是linq to xml

我把你的XML放在XML文件里了,代码如下:

 

XElement root = XElement.Load("test2.xml");
var ellist
= from element in root.Elements("ErrorType")
let errorItem
= element.Elements("ErrorItem")
from item
in errorItem
where item.HasElements && item.Element("code").Value == "1"
select item;

foreach (var item in ellist)
{
Console.WriteLine(item);
}
收获园豆:50
kyo-yo | 大侠五级 |园豆:5587 | 2010-07-26 16:23
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册