我有一个XML结构:查询不获取所有记录
<pit>
<ROW TestID="47855" ExecutionID="1510034507" TestName="USHP" AssertionName="Check News" Status="1" TestLatencyMs="5448" Date="2011-11-29 01:43:45.117" HttpCode="" Error="" TestOwner="mdk" AssertionID="119117" />
<ROW TestID="47855" ExecutionID="1510028579" TestName="USHP" AssertionName="Check News" Status="0" TestLatencyMs="7312" Date="2011-11-29 01:41:46.273" HttpCode="" Error="" TestOwner="fdxk" AssertionID="119117" />
<ROW TestID="47855" ExecutionID="1510022153" TestName="USHP" AssertionName="Check News" Status="0" TestLatencyMs="5860" Date="2011-11-29 01:39:44.153" HttpCode="" Error="" TestOwner="klo" AssertionID="119117" />
</pit>
,我尝试使用此查询来获取我的ExecutionIDs但无济于事:(我不知道什么是错
。List<int> executionIdList = new List<int>();
try
{
executionIdList = (from result in xDoc.Root.Descendants("ROW")
where result != null &&
result.Attribute("Status").Value.Equals("0", StringComparison.CurrentCultureIgnoreCase)
select result.Attributes("ExecutionID")).FirstOrDefault().Select(x => int.Parse(x.Value)).ToList();
}
我只得到与上述查询的第一个值。
nope this doesnt work..I get this object reference exception with this – Navyseal
他可以选择“行”,它会返回所有“行”元素的集合。 “坑”会返回父元素,你必须事后不必要地迭代。 –
我想我得到这个 executionIdList =(从结果xDoc.Root.Descendants( “行”) 其中结果!= NULL && result.Attribute( “状态”)。Value.Equals( “失败”,StringComparison .CurrentCultureIgnoreCase) select int.Parse(result.Attribute(“ExecutionID”)。Value))。ToList(); – Navyseal