HotboiplixSix
New Member
I have following xml structure\[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></quiz>\[/code\]and I want to convert it into CLR type using following code\[code\]public class Question{ public int ID { get; set; } 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; }}public List<Question> GetAll() { var doc = XDocument.Load(Filepath); var results = (from x in doc.Descendants("mchoice") select new Question() { ID = Convert.ToInt16(x.Element("ID")), QuestionText = x.Element("question").Value.ToString(), Answers = new List<Answer>() { //How I would fill Answer collection } }).ToList(); return results; }\[/code\]Now I have two problem with current design.[*]How I would fill the Answer collection [*]How I would handle correct answer attribute in current design.