how to read attribute data inside node in xml

karuto

New Member
i m creating an web application in that i m matching the user answer with my xml answer i have done all code and my code work fine then after i have changed my xml format so now i m unable to read the attribute of my xml file node.and below 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\]and below is my snipped 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) { if (**nodexm.InnerText.Trim()** == 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.Visible = true; label4.Text = "Your Answer is "+ ((100 * lststr1.Count) / arrXMLAnswer.Length).ToString() + "%" + "Correct"; } else { label4.Text = "Your Answer is Wrong"; } } }XmlNodeList QuestionList = docQuestionList.SelectNodes("Exam/Question");\[/code\]the above line you can see that i have read the question node but inside the question node there is attribute like Text in that my question present you can see in my xml file.\[code\]if (nodexm.InnerText.Trim() == label2.Text)\[/code\]in the above line i m matching the screen display question with my xml file question but i can't do that.label2 is used for displaying the questionhelp me please.
 
Back
Top