title: LINQ to XML nested elements query
body: <p>I have the following Questions.xml file</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;Questions&gt;
    &lt;Question&gt;
      &lt;Subject&gt;ADO.NET&lt;/Subject&gt;
      &lt;Text&gt;Which class should you use to manage multiple tables and relationships among them?&lt;/Text&gt;
      &lt;Answers&gt;
        &lt;Answer&gt;DataRow&lt;/Answer&gt;
        &lt;Answer&gt;DataView&lt;/Answer&gt;
        &lt;Answer&gt;DataTable&lt;/Answer&gt;
        &lt;Answer&gt;DataSet&lt;/Answer&gt;
      &lt;/Answers&gt;
    &lt;/Question&gt;
  &lt;/Questions&gt;
  </code></pre>
  
  <p>which I want to parse. Below are my classes and my query.</p>
  
  <pre><code>public class Question
      {
          public string Text { get; set; }
          public string Subject { get; set; }
  
          public virtual List&lt;Answer&gt; Answers { get; set; }
      }
  
      public class Answer
      {
          public string Text { get; set; }
      }
  
      static void readQuestions()
      {
          var questions = from question in XDocument.Load("Questions.xml").Descendants("Questions").Elements("Question")
                          select new Question
                          {
                              Subject = (string)question.Element("Subject"),
                              Text = (string)question.Element("Text"),
                              Answers = new List&lt;Answer&gt;(
                                  from answers in question.Elements("Answers").Elements("Answer")
                                  select new Answer
                                  {
                                      Text = (string)answers.Element("Answer")
                                  })
                          };
  
          foreach (var question in questions)
          {
              Console.WriteLine("Subject: {0}\n Text: {1}", question.Subject, question.Text);
              foreach (var answer in question.Answers)
                  Console.WriteLine("Answer: {0}", answer.Text);
          }
      }
  </code></pre>
  
  <p>The problem is it prints no Text for Answers. I searched for different nested linq to xml query examples but I can't find what's wrong with mine. Many thanks.</p>