我有以下XML,并且我需要一个查询,以便在通过特定统计信息时提取Year和Return_Value。如何在linq xml语句中使用where子句
当前的代码不起作用,因为在字典对象的一个添加语句中不能有两个where子句。有针对这个的解决方法吗?
foreach (var row in rows)
{
myHoldingsDistribution.Add(row.Descendants()
.Where(y => y.Name.LocalName == keyName)
.Select(q => q.Value).Max(),
Double.Parse(row.Descendants().Where(y => y.Name.LocalName == valueName)
.Select(q => q.Value).Max()) * multiplier);
<Table>
<Year>1</Year>
<Statistic>0 Percentile</Statistic>
<Return_Value>0.0535644000000</Return_Value>
</Table>
base {System.Xml.Linq.XContainer}: <Table>
<ALMRunResults_Year>1</ALMRunResults_Year>
<Statistic>0 Percentile</Statistic>
<Return_Value>0.0535644000000</Return_Value>
</Table>
FirstAttribute: null
HasAttributes: false
HasElements: true
IsEmpty: false
LastAttribute: null
Name: {Table}
NodeType: Element
Value: "10 Percentile0.0535644000000"
编辑
在下面的语句 - 我想最好要。凡两次过滤掉那些没有1个百分。
myHoldingsDistribution.Add(row.Descendants()
.Where(y => y.Name.LocalName == keyName)
.Select(q => q.Value).Max(),
Double.Parse(row.Descendants().Where(y => y.Name.LocalName == valueName)
.Select(q => q.Value).Max()) * multiplier);
你是什么意思“你不能有两个where子句?你从你提供的代码中得到什么错误? – StriplingWarrior 2010-12-07 17:19:08
“我想最好要。凡两次过滤掉那些没有1个百分。” - 什么阻止你?你通常可以只连锁。凡陈述在一起:`rows.Where(...),其中(...)`什么,当你试试这个,什么做的代码看起来像发生? – StriplingWarrior 2010-12-07 17:53:05