title: Read xml using LINQ and store in a list of objects
body: <p>I have xml files in the following format:</p>
  
  <pre><code>&lt;TestDataFile name="Register"&gt;
  &lt;TestSuite name="Positive"&gt;
  &lt;TestCase&gt;
    &lt;StoryName&gt;Register user&lt;/StoryName&gt;
    &lt;ScenarioName&gt;Positive&lt;/ScenarioName&gt;
    &lt;TestCaseName&gt;Register new user&lt;/TestCaseName&gt;
    &lt;ResponseCode&gt;200&lt;/ResponseCode&gt;
    &lt;UserDetails&gt;
      &lt;DateOfBirth&gt;&lt;/DateOfBirth&gt;
    &lt;/UserDetails&gt;
  &lt;/TestCase&gt;
  &lt;TestCase&gt;
    &lt;StoryName&gt;Register user&lt;/StoryName&gt;
    &lt;ScenarioName&gt;Positive&lt;/ScenarioName&gt;
    &lt;TestCaseName&gt;Register new user&lt;/TestCaseName&gt;
    &lt;ResponseCode&gt;200&lt;/ResponseCode&gt;
    &lt;UserDetails&gt;
      &lt;DateOfBirth&gt;&lt;/DateOfBirth&gt;
    &lt;/UserDetails&gt;
   &lt;/TestCase&gt;
   &lt;/TestSuite&gt;
   &lt;TestSuite name="Negative"&gt;
   &lt;TestCase&gt;
    &lt;StoryName&gt;Register user&lt;/StoryName&gt;
    &lt;ScenarioName&gt;Positive&lt;/ScenarioName&gt;
    &lt;TestCaseName&gt;Register new user&lt;/TestCaseName&gt;
    &lt;ResponseCode&gt;200&lt;/ResponseCode&gt;
    &lt;UserDetails&gt;
      &lt;DateOfBirth&gt;&lt;/DateOfBirth&gt;
    &lt;/UserDetails&gt;
    &lt;/TestCase&gt;
   &lt;TestCase&gt;
    &lt;StoryName&gt;Register user&lt;/StoryName&gt;
    &lt;ScenarioName&gt;Positive&lt;/ScenarioName&gt;
    &lt;TestCaseName&gt;Register new user&lt;/TestCaseName&gt;
    &lt;ResponseCode&gt;200&lt;/ResponseCode&gt;
    &lt;UserDetails&gt;
      &lt;DateOfBirth&gt;&lt;/DateOfBirth&gt;
    &lt;/UserDetails&gt;
    &lt;/TestCase&gt;
    &lt;/TestSuite&gt;
   &lt;/TestDataFile&gt;
  </code></pre>
  
  <p>Have many xml files in this format. And I want to read all the xmls and store in a List: List using LINQ. Trying to achieve it with the following code but not working:</p>
  
  <pre><code>foreach (string file in files)
          {
              TestDataFile testData = new TestDataFile();
              var doc = XDocument.Load(file);
              var result = doc.Descendants("TestDataFile")
                  .Select(x =&gt; new TestDataFile
                  {
                      TestSuites = new List&lt;TestSuite&gt;
                      (from ts in doc.Descendants("TestSuite")
                       select new TestSuite
                       {
                           TestCases = new List&lt;TestCase&gt;(from test in doc.Descendants("TestCase")
                                                          select new TestCase
                                                          {
                                                              StoryName = x.Element("StoryName").Value
                                                          })
                       })
                  });
  
          }
  </code></pre>
  
  <p>Can someone please help me ?</p>