I have a xml structure:
<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>
and I am trying to use this query to fetch my ExecutionIDs but to no avail 🙁 I don’t know what is wrong.
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();
}
I get only the first value with the above query.
You can fetch yout ExecutionIds from the XDocument as shown below:
The above code loads the xml from the file Sample1.xml and then fetches all the executionIDs into a list object. You can add more conditions to the query if needed like you are checking if the status value is “0”. Below is the code with the condition
Hope that helps.