private void LoadTestClass() { string xmlfil = Server.MapPath("test.xml"); XmlDocument doc = new XmlDocument(); doc.Load(xmlfil); testlista = new List<ClassQuestions>(); XmlNodeList xmlLista = doc.SelectNodes("/test/testquestion"); try { foreach (XmlNode nod in xmlLista) { ClassQuestions test = new ClassQuestions (nod.Attributes["id"].Value, nod["nr"].InnerText, nod["amountofanswers"].InnerText, nod["question"].InnerText, nod["group"].InnerText, (nod["amountofrightanswers"].InnerText) ); ClassAnswers answer = new ClassAnswers(); ClassRightAnswer rightanswer = new ClassRightAnswer(); test.Id = nod.Attributes["id"].Value; test.Nr = nod["nr"].Value; test.Group = nod["group"].InnerText; test.Question = nod["question"].InnerText; test.AmountOfAnswers = nod["amountofanswers"].Value; test.Group = nod["group"].InnerText; test.AmountOfRightAnswers = nod["amountofrightanswers"].Value; if (test.AmountOfAnswers == "1") { answer.Answer1 = nod["answer1"].InnerText; } else if (test.AmountOfAnswers == "2") { answer.Answer1 = nod["answer1"].InnerText; answer.Answer2 = nod["answer2"].InnerText; } else if (test.AmountOfAnswers == "3") { answer.Answer1 = nod["answer1"].InnerText; answer.Answer2 = nod["answer2"].InnerText; answer.Answer3 = nod["answer3"].InnerText; } else if (test.AmountOfAnswers == "4") { answer.Answer1 = nod["answer1"].InnerText; answer.Answer2 = nod["answer2"].InnerText; answer.Answer3 = nod["answer3"].InnerText; answer.Answer4 = nod["answer4"].InnerText; } else { return; } if (test.AmountOfRightAnswers == "1") { rightanswer.Rightanswer1 = nod["rightanswer1"].InnerText; } else if (test.AmountOfRightAnswers == "2") { rightanswer.Rightanswer1 = nod["rightanswer1"].InnerText; rightanswer.Rightanswer2 = nod["rightanswer2"].InnerText; } else { return; //Response.Write("Felmeddelande: Här gick något fel vid hämtade av rätt svar, kontakta din IT support!"); } testlista.Add(test); test.answerlist.Add(answer); test.rightanswerlist.Add(rightanswer); } //Repeater1.DataSource = testlista; //Repeater1.DataBind(); } catch (Exception e) { Response.Write("e"); } }
private void LoadTestClass() { string xmlfil = Server.MapPath("test.xml"); XmlDocument doc = new XmlDocument(); doc.Load(xmlfil); testlista = new List <ClassQuestions>(); XmlNodeList xmlLista = doc.SelectNodes("/test/testquestion"); try { foreach (XmlNode nod in xmlLista) { ClassQuestions test = new ClassQuestions(nod.Attributes["id"].Value, nod["nr"].InnerText, nod["amountofanswers"].InnerText, nod["question"].InnerText, nod["group"].InnerText, (nod["amountofrightanswers"].InnerText)); ClassAnswers answer = new ClassAnswers(); ClassRightAnswer rightanswer = new ClassRightAnswer(); test.Id = nod.Attributes["id"].Value; test.Nr = nod["nr"].Value; test.Group = nod["group"].InnerText; test.Question = nod["question"].InnerText; test.AmountOfAnswers = nod["amountofanswers"].Value; test.Group = nod["group"].InnerText; test.AmountOfRightAnswers = nod["amountofrightanswers"].Value; if (test.AmountOfAnswers == "1") { answer.Answer1 = nod["answer1"].InnerText; } else if (test.AmountOfAnswers == "2") { answer.Answer1 = nod["answer1"].InnerText; answer.Answer2 = nod["answer2"].InnerText; } else if (test.AmountOfAnswers == "3") { answer.Answer1 = nod["answer1"].InnerText; answer.Answer2 = nod["answer2"].InnerText; answer.Answer3 = nod["answer3"].InnerText; } else if (test.AmountOfAnswers == "4") { answer.Answer1 = nod["answer1"].InnerText; answer.Answer2 = nod["answer2"].InnerText; answer.Answer3 = nod["answer3"].InnerText; answer.Answer4 = nod["answer4"].InnerText; } else { return; } if (test.AmountOfRightAnswers == "1") { rightanswer.Rightanswer1 = nod["rightanswer1"].InnerText; } else if (test.AmountOfRightAnswers == "2") { rightanswer.Rightanswer1 = nod["rightanswer1"].InnerText; rightanswer.Rightanswer2 = nod["rightanswer2"].InnerText; } else { return; //Response.Write("Felmeddelande: Här gick något fel vid hämtade av rätt svar, kontakta din IT support!"); } testlista.Add(test); test.answerlist.Add(answer); test.rightanswerlist.Add(rightanswer); } //Repeater1.DataSource = testlista; //Repeater1.DataBind(); } catch (Exception e) { Response.Write("e"); } }