Returning multiple xml Children with same name in linq

I have the following XML and want to return all "Answers" children as List\[code\]<quiz xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="quiz.xsd"> <mchoice> <question>What is the capital city of Australia?</question> <answer>Sydney</answer> <answer correct="yes">Canberra</answer> <answer>Melbourne</answer> <answer>Gold Coast</answer> </mchoice> <mchoice> <question>Launceston is the second largest city in which Australian state?</question> <answer>Victoria</answer> <answer>New South Wales</answer> <answer correct="yes">Tasmania</answer> <answer>Western Australia</answer> </mchoice></quiz>public class Question{ public string QuestionText { get; set; } public List<Answer> Answers { get; set; }}public class Answer{ public string Answer1 { get; set; } public string Answer2 { get; set; } public string Answer3 { get; set; } public string Answer4 { get; set; }}\[/code\]I tried the following linq query,but I am stuck in Answer field\[code\]public IEnumerable<Question> GetAll() { var questions = from docs in _doc.Descendants("mchoice") select new { QuestionText = docs.Element("question").Value, Answers = docs.Descendants("answer").SelectMany(e=>e.Element("answer").Value) }; return questions; }\[/code\]
 
Back
Top