[英]Read attributes values with linq
我有一个xml文件,如下所示。 我要做的是创建一个查询,只选择具有属性“Channel”和值“Automotive”的项目。
<item>
<title>Industries</title>
<category type="Channel">Automotive</category>
<category type="Type">Cars</category>
<category type="Token">Article</category>
<category type="SpecialToken">News</category>
<guid>637f0dd7-57a0-4001-8272-f0fba60feba1</guid>
</item>
这是我的代码
var feeds = (from item in doc.Descendants("item")
where item.Element("category").Value == "Channel"
select new { }).ToList();
我尝试使用item.attribute方法但我无法获取Item中的值,只有属性Value“type”
有人可以帮我解决这个问题吗?
干杯,克里斯
我怀疑你想要:
var feeds = (from item in doc.Descendants("item")
from category in item.Elements("category")
where category.Value=="Automotive" &&
category.Attribute("type").Value == "Channel"
select item).ToList();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.