技术开发 频道

试卷的设计和实现(xml+xlst生成html试卷)


【IT168技术文档】

  前面介绍了题库的实现。有了题库就可以出题考试了。下面介绍试卷部分的设计和实现。首先看下这部分的详细类图

  首先Question对象包含分值、得分、学生答案和一个表示是否批改过的IsScored属性。并有一个对QuestionContent的引用。Questioin对象代表了某学生一张试卷上的一道题。QuestionContainer类表示的是试卷上的一个大题。比如单选题。一个大题也就是一个QuestionContainer对象,它是就是小题Question对象的集合。以此类推一张试卷也就是一个Paper对象,就是大题QuestionContainer对象的集合。注意QuesitonContainer和Paper的Score(得分)和ScoreValue(分值)都是通过对他们所有子对象Question对象的得分和分值计算得来的。Paper类的AutoScore方法是用来自动改卷的。该方法检查客观题学生答案和标准答案。根据分值给每个Question子对象自动打分。另外注意每个试卷相关的类都有一个GetxxxXML的方法。该方法就是返回对象自身的XML格式字符串。如QuestionContent类的GetContentXML实现如下
public virtual string GetContentXML() { StringBuilder builder = new StringBuilder(500); builder.Append("<" + QuestionType+ ">"); builder.Append("<Content><![CDATA[" + Content + "]]></Content>"); builder.Append("<Answer><![CDATA[" + Answer + "]]></Answer>"); builder.Append(GetChoicesXML()); builder.Append("</" + QuestionType + ">"); return builder.ToString(); } 下面是Question类的GetQuestionXML方法实现 public string GetQuestionXML() { StringBuilder builder = new StringBuilder(500); builder.Append("<Question ID=\"" + ID + "\" ScoreValue=\"" + ScoreValue + "\" Score=\"" + Score + "\" IsScored=\""+IsScored+"\">"); builder.Append("<StudentAnswer><![CDATA[" + StudentAnswer + "]]></StudentAnswer>"); builder.Append(Content.GetContentXML()); //Content为QuestionContent对象 builder.Append("</Question>"); return builder.ToString(); }
0
相关文章