 悬赏园豆:50
                [已解决问题] 
            
                    解决于 2010-07-27 10:03
                悬赏园豆: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
不是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);
}