【发布时间】:2012-05-12 07:00:10
【问题描述】:
我已经创建了一个 asp.net 页面,它正在读取一些文本的 xml 文件节点。 下面是我的 xml 文件的样子。
<?xml version="1.0" encoding="utf-8" ?>
<Questions>
<Question id="1">What is IL code </Question>
<Answer1>Half compiled,Partially compiled code </Answer1>
<Question id="2">What is TL code </Question>
<Answer2>Half compiled,Partially compiled code </Answer2>
</Questions>
我还创建了一个 .aspx 页面,该页面有一个显示问题的标签和一个文本,用户可以在其中输入他/她对该特定问题的答案,并且在一个按钮下方有一些代码,如下所示
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() == lblQuestion.Text)
{
if (Answer.NextSibling.InnerText.Trim() == txtUserAnswer.Text)
{
// This is right Answer
TextBox1.Text = "right";
}
else
{
// This is wrong Answer
TextBox1.Text = "wrong";
}
}
}
我想显示用户为特定问题输入的答案的百分比。
例如假设问题是......什么是 IL 代码?并且用户输入答案作为部分编译..所以我只想检查我的 xml 答案节点中输入的关键字。
如果用户答案与节点答案匹配,则以百分比显示答案的准确性。
请帮忙...
谢谢,
【问题讨论】:
-
您的 XML 文件 有 有这种格式吗?每个问题都有一个元素,答案在该元素中,而不是在问题和答案之间交替,会更明智。它与问题无关(XML 部分都不是——你真的只是对字符串相似性感兴趣),但它会让你的生活更轻松。
-
补充 Jon 的评论 - 每个答案都有不同的元素类型似乎特别糟糕(与问题相反,它们都使用相同的元素类型)
-
你能推荐一个例子,以便我可以使用它....感谢你宝贵的 cmets