title: Parsing XML with LINQ in C#
body: <p>I am trying to do a mapping between C# and XML with LINQ. Currently, I have a class defined in C# that looks like this:</p>
  
  <p><strong>Item.cs</strong></p>
  
  <pre><code>public class Item
  {
    public string DepartmentName { get; set; }
    public Dictionary&lt;string, string&gt; DepartmentNames { get; set; }
  
    public string Name { get; set; }
    public Dictionary&lt;string, string&gt; Names { get; set; }
  }
  </code></pre>
  
  <p>My XML file looks like this:</p>
  
  <p><strong>departments.xml</strong></p>
  
  <pre><code>&lt;Departments&gt;
    &lt;Department Name="Sports" Title="Sports Department" Path="/sports" en-us="Sports" de-de="Sport"&gt;
      &lt;Item Name="Football" en-us="Football" de-de="Fußball" es-mx="" /&gt;
      &lt;Item Name="TennisBall" en-us="Tennis Ball" de-de="Tennisball" /&gt;
    &lt;/Department&gt;
  
    &lt;Department Name="Automotive" Title="Automotive Department" Path="/autos" en-us="Automotive" de-de="kraftfahrtechnisch"&gt;
      &lt;Item Name="Oil" en-us="Oil" de-de="Öl" /&gt;
      &lt;Item Name="Tires" en-us="Tires" de-de="Bereifung" es-mx="Ruedas" /&gt;
    &lt;/Department&gt;
  &lt;/Departments&gt;
  </code></pre>
  
  <p>Basically, I have some values I want to load into a definite properties. Then, I have a list of attributes I know ("en-us", "de-de", "es-mx") that I want to load into Dictionaries. Currently, I have the following:</p>
  
  <pre><code>var items = XDocument.Parse(File.ReadAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"App_Data\Items.xml")))
    .Element("Departments")
    .Elements("Department")
    .Elements("Item")
    .Select(e =&gt; new Item
    {
      DepartmentName = ?,
      DepartmentNames = ?,
      Name = e.Attribute("Name").Value,
      Names = ?
    }).ToList();
  </code></pre>
  
  <p>I'm not sure how to load the properties from a) The parent elements b) Load the Dictionary object. Is this even possible with LINQ? Essentially, I'm trying to flatten out my data structure in-memory.</p>