title: Parsing complex XML with LINQ
body: <p>I have the following XML that I have generated:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;Employees&gt;
    &lt;Employee&gt;
      &lt;First_Name&gt;John&lt;/First_Name&gt;
      &lt;Last_Name&gt;Doe&lt;/Last_Name&gt;
      &lt;TSR&gt;12345&lt;/TSR&gt;
      &lt;Assignments&gt;
        &lt;Assignment&gt;
          &lt;Division&gt;California&lt;/Division&gt;
          &lt;Project&gt;Sales&lt;/Project&gt;
          &lt;Title&gt;Agent&lt;/Title&gt;
          &lt;Start_Date PartTime="False"&gt;6/13/2012&lt;/Start_Date&gt;
          &lt;Supervisor&gt;Jack Moore&lt;/Supervisor&gt;
          &lt;Trainer&gt;&lt;/Trainer&gt;
          &lt;End_Date TrainingNoShow="False"&gt;3/1/2016&lt;/End_Date&gt;
          &lt;Separation_Reason&gt;Job was not a fit&lt;/Separation_Reason&gt;
          &lt;Termination&gt;True&lt;/Termination&gt;
          &lt;Comments&gt;
  August 2, 2016: &lt;/Comments&gt;
        &lt;/Assignment&gt;
      &lt;/Assignments&gt;
    &lt;/Employee&gt;
  &lt;/Employees&gt;
  </code></pre>
  
  <p>This is the code I'm using to pull it, however this gives me a System.NullReferenceException:</p>
  
  <pre><code>private void ImportXMLFile(string p_strFileName) {
      XDocument xEmployees = XDocument.Load(p_strFileName);
      var employees = from employee in xEmployees.Descendants("Employee")
          select new AnEmployee 
      {  //on this line
          FirstName = employee.Element("First_Name").Value,
          LastName = employee.Element("Last_Name").Value,
          EmpID = employee.Element("TSR").Value,
          History = new List&lt;AnAssignment&gt;(from assignment in employee.Descendants("Assignment")
                                           select new AnAssignment
                                           {
                                              Division = assignment.Element("Division").Value,
                                              Project = assignment.Element("Project").Value,
                                              Title = assignment.Element("Title").Value,
                                              StartDate = DateTime.Parse(assignment.Element("Start_Date").Value),
                                              isPartTime = bool.Parse(assignment.Element("Start_Date").Attribute("PartTime").Value),
                                              EndDate = DateTime.Parse(assignment.Element("End_Date").Value),
                                              Supervisor = assignment.Element("Supervisor").Value,
                                              Separation = assignment.Element("SeparationReason").Value,
                                              isTerminated = bool.Parse(assignment.Element("Termination").Value),
                                              Comments = assignment.Element("Comments").Value
  
                                           })
      };
      foreach(AnEmployee e in employees) {
          EmployeeCollection.add(e);
      }
  }
  </code></pre>
  
  <p>It's doesn't seem to be anything regarding the Employee element, so I'm wondering what I'm doing wrong on the Assignment Element. Everything from supervisor to Termination is optional (aka it may or may not appear in a particular assignment.</p>