我想从使用LINQ的XML文件读取值。 这真的是我第一次尝试使用LINQ与普通的C#/ .Net方法。使用LINQ读取XML元素
我的XML看起来是这样的:
<Description>
<Account Green="A" White="D">House</Account>
<Account Green="B" White="D">Car</Account>
</Description>
这是我使用的LINQexpression。我想读House的价值,换句话说,属性A和D的元素。
var feeds = (from item in doc.Descendants("Description")
from category in item.Elements("Account")
let attribute = category.Attribute("Green")
let xAttribute = category.Attribute("White")
where attribute != null && (xAttribute != null && (xAttribute.Value == "A"
&& attribute.Value == "D")) select item.Value).ToString();
我弄不明白我做错了什么。 任何帮助表示赞赏。
它是XmlElement还是XElement? – Gqqnbig 2017-03-13 23:22:07