How to compare a user's multiple answers with my XML file?

xam666

New Member
I'm creating a web page of interviews, where the user can answer a specific question mentioned on the screen inside the textbox. I have a check button. On click of this button I need to compare the answer entered in the specific question textbox and usually display accuracy of answer in percentage by comparing with my XML file's answer for specific question.This is my XML file"\[code\]<?xml version="1.0" encoding="utf-8" ?> <Questions> <Question id="1">What is IL code </Question> <Answer id="1">Half compiled, Partially compiled code </Answer> <Question id="2">What is JIT </Question> <Answer id="2">IL code to machine language </Answer> <Question id="3">What is CLR </Question> <Answer id="3">Heart of the engine , GC , compilation , CAS(Code access security) , CV ( Code verification) </Answer> </Questions>\[/code\]This is my form:
mpmXS.jpg
Below is my code for my check button, where I have only compared with a single label and textbox. It works.\[code\]XmlDocument docQuestionList = new XmlDocument();// Set up the XmlDocument //docQuestionList.Load(@"C:\Users\Administrator\Desktop\questioon\questioon\QuestionAnswer.xml"); //Load the data from the file into the XmlDocument //XmlNodeList AnswerList = docQuestionList.SelectNodes("Questions/Question");foreach (XmlNode Answer in AnswerList){ if (Answer.InnerText.Trim() == Label2.Text) { string[] arrUserAnswer = TextBox1.Text.Trim().ToLower().Split(' '); string[] arrXMLAnswer = Answer.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) { TextBox1.Text = ((100 * lststr1.Count) / arrXMLAnswer.Length).ToString() + "%"; } else { TextBox1.Text = "0 %"; } }}\[/code\]As you can see, I have only compared the value for one question and respective answer, but I would prefer that this is not hard-coded. Instead, it should take the question and the respective textbox answer and compare with my XML file. How might I achieve my goal?
 
Back
Top