I have a linq query which iterates over hundreds of XML elements to count the quantity of specific tools used in a collection of tools.
However, the qty element in the tools xelement collection, which should contain a number, occasionally contains text such as "As required" as opposed to a specific number. This clearly causes problems.
Is there a simple additional step i can put into this linq query (i'm not good with linq) that will either ignore non-number values, or filter them out?
Linq query is:
Dictionary<int, int> dict = listTools.Descendants("tool")
.GroupBy(x => (int)x.Element("id"), y => (int)y.Element("qty"))
.ToDictionary(x => x.Key, y => y.Sum());