How to store duplicate data from xml file in C# -
i'm having xml file like
<root>  <child val1="1" val2="0"/>  <child val1="1" val2="2"/>  <child val1="1" val2="3"/>  <child val1="1" val2="4"/>  <child val1="1" val2="5"/>  <child val1="6" val2="0"/>  <child val1="7" val2="0"/> </root>   i need store data in temporary storage ( namely dictionary) sort of manipulations . cannot use dictionary here because dictionary not support same keys. can 1 suggest me better way store data?
well, use dictionary<int, list<int>> - or storage (no changes) use linq's tolookup method build multi-valued map easily. (using linq xml):
var lookup = doc.descendants("child")                 .tolookup(x => (int) x.attribute("val1"),                           x => (int) x.attribute("val2"));  // iterate 5 times, printing 0, 2, 3, 4, 5  foreach (var value in lookup[1]) {     console.writeline(value);  }   edit: display all information, you'd like:
foreach (var grouping in lookup) {     foreach (var value in grouping)     {         console.writeline("{0} {1}", grouping.key, value);     } }      
Comments
Post a Comment