I have an XElement structured as follows:
<items> <item> <param1>A</param1> <param2>123</param2> </item> <item> <param1>B</param1> <param2>456</param2> </item> <item> <param1>A</param1> <param2>789</param2> </item> <item> <param1>B</param1> <param2>101112</param2> </item> </items>
I want to get a dictionary in which the keys are attached to <param1> (A, B), and the value is lists of correlation elements:
A -> <item><param1>A</param1><param2>123</param2></item> <item><param1>A</param1><param2>789</param2></item> B -> <item><param1>B</param1><param2>456</param2></item> <item><param1>B</param1><param2>101112</param2></item>
I tried with this:
var grouped = xItems.Descendants("item").GroupBy(r => r.Element("param1")) .ToDictionary(g => g.Key, g => g.ToList());
But I still get 4 elements, a set of key values ββwith duplicate keys, and not a 2-element dictionary, as I would like. Any help?
source share