[英]How to get some data using a conditional in LINQ to XML?
我有一個Enumerable和一個int數組,我只想獲取數組中存在ObjectiveID的數據。 例如:
如果這是我的數組:1,2,3在我的XML文件中,我有一些節點,其中包含:1,2,3,4,5,6
該程序必須獲得1、2、3,因為它存在於數組中。 我怎樣才能做到這一點? 我當時計划使用氣囊來去除每個氣囊,但是我知道有一種更好的方法。
這是代碼的一部分:
XDocument xdoc = XDocument.Load(path);
var conditions = from c in xdoc.Descendants("Condition")
select new
{
ObjectiveID = (int)c.Attribute("ObjectiveID"),
TypeID = (int)c.Attribute("TypeID"),
ProblemID = (int)c.Attribute("ProblemID"),
Ranges = (from r in c.Descendants("Range")
select new
{
Decimals = (int)r.Attribute("Decimals"),
Min = (decimal)r.Attribute("Min"),
Max = (decimal)r.Attribute("Max")
}).ToArray(),
};
值1-6到底從哪里來還不清楚,但是您可能只想要一個where
子句,例如:
where array.Contains((int) c.Attribute("id"))
或類似的東西。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.