check multiple data with my xml file

coachoutlet3lqq

New Member
i m creating an window application in that i have one label for display the question and one textbox for answering the respective question.then 3 button for check the answer with my xml file and one button for next question and one button for previous question.this is my xml file\[code\]<?xml version="1.0" encoding="utf-8" ?><Exam> <Question number="1" Text="What is IL Code"> <Answer Text="Half compiled, Partially compiled code"> </Answer> </Question> <Question number="2" Text="What is JIT"> <Answer Text="IL code to machine language"> </Answer> </Question> <Question number="3" Text="What is CLR"> <Answer Text="Heart of the engine , GC , compilation , CAS(Code access security) , CV ( Code verification)"> </Answer> </Question></Exam> \[/code\]now on button click i want to check the user answer with my xml answer and this part i have done but little problem whenever for the first question that is what is il code for this my code work properly and when the question is changed then my code unable to take the second question every time it take first question and compare with this so how can i achieve this?below is my snipped code\[code\]string[] arrUserAnswer = textBox1.Text.Trim().ToLower().Split(' '); do { XmlReader reader = XmlReader.Create(@"E:\ferozProject\WindowsFormsApplication1\WindowsFormsApplication1\QuestionFile.xml"); reader.Read(); reader.ReadToFollowing("Question"); reader.MoveToContent(); que = reader.GetAttribute("Text"); reader.ReadToFollowing("Answer"); reader.MoveToContent(); string[] arrXMLAnswer = reader.GetAttribute("Text").ToString().Trim().ToLower().Split(' '); List<string> lststr1 = new List<string>(); if (label2.Text == que) { abc = 1; foreach (string nextStr in arrXMLAnswer) { if (Array.IndexOf(arrUserAnswer, nextStr) != -1) { lststr1.Add(nextStr); } } if (lststr1.Count > 0) { label4.Visible = true; label4.Text = "Your Answer is " + ((100 * lststr1.Count) / arrXMLAnswer.Length).ToString() + "%" + "Correct"; } else { textBox1.Text = "0 %"; } } else { reader.ReadToNextSibling("Question"); } } while (abc <= 0); abc = 0;\[/code\]i have also used the second another method for that but in which the code unable to find out my question as because of i have written the question inside the question node, below is my another code.\[code\]XmlDocument docQuestionList = new XmlDocument();// Set up the XmlDocument // docQuestionList.Load(@"E:\ferozProject\WindowsFormsApplication1\WindowsFormsApplication1\QuestionFile.xml"); //Load the data from the file into the XmlDocument // XmlNodeList QuestionList = docQuestionList.SelectNodes("Exam/Question"); foreach (XmlNode nodexm in QuestionList) { string obj = nodexm.SelectNodes("Text").ToString(); if (obj == label2.Text) { string[] arrUserAnswer = textBox1.Text.Trim().ToLower().Split(' '); string[] arrXMLAnswer = nodexm.NextSibling.InnerText.Trim().ToLower().Split(' '); List<string> lststr1 = new List<string>(); foreach (string nextStr in arrXMLAnswer) { if (Array.IndexOf(arrUserAnswer, nextStr) != -1) { lststr1.Add(nextStr); } } if (lststr1.Count > 0) { label4.Text = "Your Answer is " + ((100 * lststr1.Count) / arrXMLAnswer.Length).ToString() + "%" + "Correct"; } else { textBox1.Text = "0 %"; } } }\[/code\]please help me in any one method
 
Back
Top