title: manipulate XML document with linq
body: <p>I have the following xml that i need to transfom to an other form. I have a C# code that does it but it has a bug with is hard to track. I beleive Linq could offer a more error prone way to do this. 
  input xml:</p>
  
  <pre><code>&lt;NewDataSet&gt;
    &lt;Table&gt;
      &lt;RoleId&gt;5&lt;/RoleId&gt;
      &lt;Code&gt;DP&lt;/Code&gt;
      &lt;Description&gt;Process data&lt;/Description&gt;
      &lt;Task&gt;Validate indices&lt;/Task&gt;
      &lt;TaskId&gt;12&lt;/TaskId&gt;
      &lt;Country&gt;BE&lt;/Country&gt;
      &lt;CountryId&gt;3&lt;/CountryId&gt;
    &lt;/Table&gt;
    &lt;Table&gt;
      &lt;RoleId&gt;5&lt;/RoleId&gt;
      &lt;Code&gt;DP&lt;/Code&gt;
      &lt;Description&gt;Process data&lt;/Description&gt;
      &lt;Task&gt;calculate indices&lt;/Task&gt;
      &lt;TaskId&gt;11&lt;/TaskId&gt;
      &lt;Country&gt;US&lt;/Country&gt;
      &lt;CountryId&gt;4&lt;/CountryId&gt;
    &lt;/Table&gt;
    &lt;Table&gt;
      &lt;RoleId&gt;5&lt;/RoleId&gt;
      &lt;Code&gt;DP&lt;/Code&gt;
      &lt;Description&gt;Process data&lt;/Description&gt;
      &lt;Task&gt;Calculate indices&lt;/Task&gt;
      &lt;TaskId&gt;11&lt;/TaskId&gt;
      &lt;Country&gt;UK&lt;/Country&gt;
      &lt;CountryId&gt;5&lt;/CountryId&gt;
    &lt;/Table&gt;
    &lt;Table&gt;
      &lt;RoleId&gt;1&lt;/RoleId&gt;
      &lt;Code&gt;DR&lt;/Code&gt;
      &lt;Description&gt;View data&lt;/Description&gt;
      &lt;Task&gt;View Reports&lt;/Task&gt;
      &lt;TaskId&gt;9&lt;/TaskId&gt;
      &lt;Country&gt;SC&lt;/Country&gt;
      &lt;CountryId&gt;17&lt;/CountryId&gt;
    &lt;/Table&gt;
    &lt;Table&gt;
      &lt;RoleId&gt;1&lt;/RoleId&gt;
      &lt;Code&gt;DR&lt;/Code&gt;
      &lt;Description&gt;View data&lt;/Description&gt;
      &lt;Task&gt;View Basics&lt;/Task&gt;
      &lt;TaskId&gt;10&lt;/TaskId&gt;
      &lt;Country&gt;SC&lt;/Country&gt;
      &lt;CountryId&gt;17&lt;/CountryId&gt;
    &lt;/Table&gt;
    &lt;Table&gt;
      &lt;RoleId&gt;1&lt;/RoleId&gt;
      &lt;Code&gt;DR&lt;/Code&gt;
      &lt;Description&gt;View data&lt;/Description&gt;
      &lt;Task&gt;Download data&lt;/Task&gt;
      &lt;TaskId&gt;11&lt;/TaskId&gt;
      &lt;Country&gt;FR&lt;/Country&gt;
      &lt;CountryId&gt;15&lt;/CountryId&gt;
    &lt;/Table&gt;
  &lt;/NewDataSet&gt;
  </code></pre>
  
  <p>and the output that i need is as follow:</p>
  
  <pre><code>&lt;NewDataSet&gt;
   &lt;Table&gt;
      &lt;RoleId&gt;5&lt;/RoleId&gt;
      &lt;Code&gt;DP&lt;/Code&gt;
      &lt;Description&gt;Process data&lt;/Description&gt;
      &lt;Task&gt;Validate indices,Calculate indices,&lt;/Task&gt;
      &lt;TaskId&gt;12,11&lt;/TaskId&gt;
      &lt;Country&gt;BE,US,UK&lt;/Country&gt;
      &lt;CountryId&gt;3,4,5&lt;/CountryId&gt;
    &lt;/Table&gt;
    &lt;Table&gt;
      &lt;RoleId&gt;1&lt;/RoleId&gt;
      &lt;Code&gt;DR&lt;/Code&gt;
      &lt;Description&gt;Process data from commercial fisheries&lt;/Description&gt;
      &lt;Task&gt;View Reports,View Basics,View data&lt;/Task&gt;
      &lt;TaskId&gt;9,10,11&lt;/TaskId&gt;
      &lt;Country&gt;SC,FR&lt;/Country&gt;
      &lt;CountryId&gt;17,15&lt;/CountryId&gt;
    &lt;/Table&gt;
  &lt;/NewDataSet&gt;
  </code></pre>
  
  <p>As you can see, the elements are group by RoleId, Code and Description.</p>
  
  <p>I have created a custum object to project the xml element to </p>
  
  <pre><code>public class Table
  {
     public int RoleId {get;set;}
     public string Code  {get;set;}
     public string  Description {get;set;}
     public string Task {get;set;}
     public int TaskId {get;set;}
     public string  Country {get;set;}
     public int CountryId  {get;set;}
  
  }
  </code></pre>
  
  <p>The idea is then to use this list of custum object to recreate an xml document. But i was thinking there could be a more straigforward way. without the need to use the custum object list.</p>
  
  <p>The rest of the element are simply concatenated. I hope someone have an idea sugestion of how this could be achieved using Linq to XML.
  many thanks in advance</p>