WEB开发网
开发学院WEB开发ASP 利用ASP+XML架设在线考试系统 阅读

利用ASP+XML架设在线考试系统

 2002-07-04 11:10:10 来源:WEB开发网   
核心提示:利用asp + xml 架设在线考试系统<-此程序非本人原创>使用这个在线的考试系统,我们能处理任何类型在线测试,利用ASP+XML架设在线考试系统, 尽管我们一般是用传统方式实现,读者非常希望将,时间( 例如5 分钟) 结束, 关于终结, 如果从总体上考虑, 所有问题都储存在服务器( 它可能在数据库里)
利用asp + xml 架设在线考试系统

<-------------此程序非本人原创-------->
 
使用这个在线的考试系统,我们能处理任何类型在线测试。 尽管我们一般是用传统方式实现,读者非常希望将。

如果从总体上考虑。 所有问题都储存在服务器( 它可能在数据库里) 里面的的xml 文件里。 用户准备花费考试,然后用户测试的通体将通过微软的XML HTTP 组件传送到浏览器。 使用同一个XML HTTP 组件,每当用户请求一个问题的时候,那些问题内容被从服务器解释并且显示在页上。 对用户的任何问题,你所选择的答案会被储存在客户端。 



一次考试的持续时间是5 分钟。 没有回答不了,你可以使用NEXT回答下洋问题。 一旦用户启动考试,所有问题目录将来自服务器。 所给问题的Id 每请求到服务器以来在内目录在客户拿给并且给服务器派内储存。 服务器将返回问题内容,符合问题Id,从xml 文件。 当用户选择任何一个答案时,体制将在那些应答表里储存和在在客户边里的选择表里。 用户最后已经选择的正确的答案,应答表用来并不地检查。 选择表在那里是以便系统将自动选择用户已经选择了的选择 ( 例如用户点击以前的按钮) 考试将结束或者用户点击终结按钮或者首先来,时间( 例如5 分钟) 结束。 关于终结,系统将计算并不右边答案的并且展示它。 那些以下的文件被在在线的考试系统里使用:

OLExam.html

<html>
<script>
 var objxmlhttp,objXmlDOM;
 var aQuest; //to store question ids
 var aAnswer = new Array(); // to track the result
 var aSelected = new Array(); // to store user's response
 var count = 0; //to store the current question no
 var ansSel = 0; //to store user's selection
 var ExamDuration = 5 * 60 ; // 5 minutes
 var timerID; //to store the setInterval fun's id
 var radIndex = -1; //to store the selected radio's index

 //constructor like function
 //here XML objects are created and
 //No of questions as well as question ids list
 //are fetched from the server.
 function init(){
  objXmlHTTP = new ActiveXObject("Microsoft.XMLHTTP");
  objXmlDOM = new ActiveXObject("Microsoft.XMLDOM");
  objXmlHTTP.open("POST","OLExam.asp?Action=Start",false);
  objXmlHTTP.send("");
  temp =objXmlHTTP.ResponseText;
  aQuest = temp.split(",");

  //initialize the user's answers list
  for(i=0;i<aQuest.length; i++){
   aAnswer[i] = 0; // 0 for wrong; 1 for right answer
   aSelected[i] = -1; // to store the radio's index
  }

  if(count < aQuest.length) {
   url = "OLExam.asp?Action=NextQ&QNo=" + aQuest[count];
   objXmlHTTP.open("POST", url ,false);
   objXmlHTTP.send("");
   objXmlDOM.loadXML(objXmlHTTP.ResponseText);
   
   //parse the response content fetched from the server
   //and display the question
   parseQ();
  }
  
  //change the Start button's caption and its click event
  document.frm.btnFinish.value = "Finish the Exam";
  document.frm.btnFinish.onclick = showResult; //function
  
  //start the timer
  timerID = setInterval("timer()",1000);
 }

 function getPReQ() {
  //update the user's answers list
  checkAnswer();
  
  //decrement the question no - i.e. to previous Question
  count--;
  
  //stop the timer
  clearInterval(timerID);
  
  //fetch the question for the aQuest[count] id
  url = "OLExam.asp?Action=NextQ&QNo=" + aQuest[count];
  objXmlHTTP.open("POST",url ,false);
  objXmlHTTP.send("");
  objXmlDOM.loadXML(objXmlHTTP.ResponseText);

  //parse the response content fetched from the server
  //and display the question
  parseQ();
  
  //start the timer
  timerID = setInterval("timer()",1000);
 }

 function getNextQ() {
  //update the user's answers list
  checkAnswer();

  //increment the question no - i.e. to next Question
  count++;

  //stop the timer
  clearInterval(timerID);

  url = "OLExam.asp?Action=NextQ&QNo=" + aQuest[count];
  objXmlHTTP.open("POST", url ,false);
  objXmlHTTP.send("");
  objXmlDOM.loadXML(objXmlHTTP.ResponseText);

  //parse the response content fetched from the server
  //and display the question
  parseQ();

  //start the timer
  timerID = setInterval("timer()",1000);
 }

 function parseQ(){
  //fetch the question from theXML Object
  //format the display   
  strOut = "<table border=0 align=center width=80%>";
  strOut += "<tr><td colspan=2><b>";
  strOut += "Question No: " + (count+1) + " of ";
  strOut += aQuest.length + "</b></td></tr>";
  strOut += "<tr><td colspan=2> </td></tr>";

  temp = objXmlDOM.selectSingleNode("data/qtext").text;

  strOut += "<tr><td colspan=2><b>"+temp+"</b></td></tr>";
  strOut += "<tr><td colspan=2> </td></tr>";

  Nodes = objXmlDOM.selectNodes("data/choice");

  for(i=0;i<Nodes.length;i++){
   strOut += "<tr><td align=center width=10%>";
   strOut += "<input type=radio name=ansUsr ";
   strOut += " send the output to the client
 Response.Write (strXML)
end if
%>





QBank.xml

<?xml version="1.0"?>
<data>
 <question id="1">
  <qtext>What does KB stand for?</qtext>
  <choices>
   <choice>Kilo Bits</choice>
   <choice>Key Board</choice>
   <choice>Kilo Bytes</choice>
   <choice>None</choice>
  </choices>
  <answer>3</answer>
 </question>
 <question id="2">
  <qtext>CPU stands for</qtext>
  <choices>
   <choice>Central Processing Unit</choice>
   <choice>Central Power Unit</choice>
   <choice>Core Processing Unit</choice>
   <choice>Core Power Unit</choice>
  </choices>
  <answer>1</answer>
 </question>
 <question id="3">
  <qtext>1 KB equals</qtext>
  <choices>
   <choice>1000 Bytes</choice>
   <choice>1024 Bytes</choice>
   <choice>1000 Bits</choice>
   <choice>1024 Bits</choice>
   <choice>Nothing</choice>
  </choices>
  <answer>2</answer>
 </question>
 <question id="4">
  <qtext>RAM is </qtext>
  <choices>
   <choice>Random access Modifier</choice>
   <choice>Primary Memory</choice>
   <choice>Secondary Memory</choice>
   <choice>Read And Modify</choice>
  </choices>
  <answer>2</answer>
 </question>
 <question id="5">
  <qtext>Hard Disk is </qtext>
  <choices>
   <choice>Hard to break</choice>
   <choice>Primary Memory Storage</choice>
   <choice>Temporary Memory Storage</choice>
   <choice>Secondary Memory Storage</choice>
  </choices>
  <answer>4</answer>
 </question>
 <question id="6">
  <qtext>Computer Monitor is used </qtext>
  <choices>
   <choice>To monitor activities</choice>
   <choice>To control Computer</choice>
   <choice>As display unit</choice>
   <choice>None</choice>
  </choices>
  <answer>3</answer>
 </question>
 <question id="7">
  <qtext>XML stands for</qtext>
  <choices>
   <choice>Extended Markup Language</choice>
   <choice>Extended Model Language</choice>
   <choice>Extensible Markup Language</choice>
   <choice>Extensible Model Language</choice>
  </choices>
  <answer>3</answer>
 </question>
 <question id="8">
  <qtext>ASP stands for</qtext>
  <choices>
   <choice>Active Server Page</choice>
   <choice>application Service Provision</choice>
   <choice>As Soon as Possible</choice>
   <choice>All</choice>
  </choices>
  <answer>1</answer>
 </question>
</data>


Tags:利用 ASP XML

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接