インタビューのWebページを作成しています。このページでは、ユーザーはテキストボックス内の画面に記載されている特定の質問に答えることができます。チェックボタンがあります。このボタンをクリックすると、特定の質問のテキストボックスに入力された回答を比較する必要があります。通常、特定の質問に対するXMLファイルの回答と比較して、回答の精度をパーセンテージで表示します。
これは私のXMLファイルです」
<?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>
これは私のフォームです:
以下は、チェックボタンのコードです。ここでは、単一のラベルとテキストボックスとのみ比較しています。できます。
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 %";
}
}
}
ご覧のとおり、1つの質問とそれぞれの回答の値を比較しただけですが、これはハードコーディングされていないことをお勧めします。代わりに、質問とそれぞれのテキストボックスの回答を受け取り、私のXMLファイルと比較する必要があります。どうすれば目標を達成できますか?