<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>klkl &#187; Kquestion</title>
	<atom:link href="http://klkl.co.uk/category/kquestion/feed/" rel="self" type="application/rss+xml" />
	<link>http://klkl.co.uk</link>
	<description>it's easy to type</description>
	<lastBuildDate>Mon, 14 May 2012 22:39:11 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>PHP Daylight Savings Error When Dealing With Timestamps</title>
		<link>http://klkl.co.uk/2008/07/10/php-daylight-savings-error-when-dealing-with-timestamps/</link>
		<comments>http://klkl.co.uk/2008/07/10/php-daylight-savings-error-when-dealing-with-timestamps/#comments</comments>
		<pubDate>Thu, 10 Jul 2008 20:44:11 +0000</pubDate>
		<dc:creator>klkl</dc:creator>
				<category><![CDATA[Internet]]></category>
		<category><![CDATA[Kquestion]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[BST]]></category>
		<category><![CDATA[DST]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Timestamp]]></category>

		<guid isPermaLink="false">http://klkl.co.uk/?p=42</guid>
		<description><![CDATA[<p>Last night I was working on determining how long a user had been logged into a PHP application but was having a problem with subtracting timestamps and this is how I solved it.</p>
<p>I was storing two timestamps (as a UNIX timestamp) in the database. One designating the date-time the user logged into the application and the other the date-time of the last activity the user performed. Because I was using UNIX timestamps, which are just the number of seconds sine the UNIX epoch, I subtracted one from the other and used that difference as the input to the PHP function date().</p>
<p>I couldn&#8217;t for the life of me work out why the date function was saying that I was logged in for an hour longer than I should have been and it was driving me crazy. It turns out that the reason was that my timezone locale setting in PHP is &#8216;Europe/London&#8217; and that this causes the date function to adjust for British Summer Time (GMT + 1) thus when I used my timestamp difference in the date() function it translated the difference into a readable format but also added an extra hour.</p>
<p>The solution is to use gmdate() which is identical to the date() function except that the time returned is in Grenwich Mean Time format.</p>
]]></description>
			<content:encoded><![CDATA[<p>Last night I was working on determining how long a user had been logged into a PHP application but was having a problem with subtracting timestamps and this is how I solved it.</p>
<p>I was storing two timestamps (as a UNIX timestamp) in the database. One designating the date-time the user logged into the application and the other the date-time of the last activity the user performed. Because I was using UNIX timestamps, which are just the number of seconds sine the UNIX epoch, I subtracted one from the other and used that difference as the input to the PHP function date().</p>
<p>I couldn&#8217;t for the life of me work out why the date function was saying that I was logged in for an hour longer than I should have been and it was driving me crazy. It turns out that the reason was that my timezone locale setting in PHP is &#8216;Europe/London&#8217; and that this causes the date function to adjust for British Summer Time (GMT + 1) thus when I used my timestamp difference in the date() function it translated the difference into a readable format but also added an extra hour.</p>
<p>The solution is to use gmdate() which is identical to the date() function except that the time returned is in Grenwich Mean Time format.</p>
]]></content:encoded>
			<wfw:commentRss>http://klkl.co.uk/2008/07/10/php-daylight-savings-error-when-dealing-with-timestamps/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Thoughts on Database Structure</title>
		<link>http://klkl.co.uk/2007/11/21/thoughts-on-database-structure/</link>
		<comments>http://klkl.co.uk/2007/11/21/thoughts-on-database-structure/#comments</comments>
		<pubDate>Wed, 21 Nov 2007 12:58:50 +0000</pubDate>
		<dc:creator>klkl</dc:creator>
				<category><![CDATA[Kquestion]]></category>

		<guid isPermaLink="false">http://klkl.co.uk/?p=9</guid>
		<description><![CDATA[<p>I&#8217;ve done quite a bit of work on the project (see the progress page) but I wasn&#8217;t sure what to document first because the application is going to store all the information in a MySQL database I thought I&#8217;d talk about the structure of the base (or most important) tables.</p>
<p><span id="more-9"></span><strong>Questions</strong></p>
<p>The application is going to revolve around questions so there obviously needs to be a table to store some of the details of each question. Each question will need an ID it will have some question text, it will also have a correct answer.</p>
<p><span id="more-9"></span></p>
<p>The answers are stored in another table so the question table will hold an identifier that relates to the correct answer instead of the correct answer itself. This is because the same answer may be used more than once (TRUE / FALSE for example) and referencing the answers instead of replicating them will save space.</p>
<p>Some question types are complicated so there will also be instructions to go with the question so the person knows what is expected of them.  Again these will be repeated several times and so stored in another table.</p>
<p>So the Question table would look something like;</p>
<ul>
<li>Q_Questions
<ul>
<li>ID: int(4)</li>
</ul>
<ul>
<li>QText: text</li>
</ul>
<ul>
<li>CorrectAnswer: int(4)</li>
</ul>
<ul>
<li>Instructions: int(4)</li>
</ul>
</li>
</ul>
<p><strong>Answers</strong></p>
<p>The answers table is much simpler seen as it only needs to store the actual answer and its ID.</p>
<ul>
<li>Q_Answers
<ul>
<li>ID: int(4)</li>
<li>AText: text</li>
</ul>
</li>
</ul>
<p><strong>Lookup Table</strong></p>
<p>A question may have more than one answer and an answer may be suggested for more than one question. This is modeled using a look up table is used. The look up table is a table that records which answers appear with which questions. This is achieved with two one-to-many relationships. The look up table has two fields&#8230;</p>
<ul>
<li>Q_QAL
<ul>
<li>QID: int(4)</li>
<li>AID: int(4)</li>
</ul>
</li>
</ul>
<p>&#8230;one that refers to the ID of the question and another that refers to the ID of the answer. Both fields are assigned as the primary key, this ensures that there are no duplicate entries. Whenever you want to associate an answer with a particular question you create a record in this table with the respective IDs. This way you can have as many or few answers associated with a question.</p>
<p><strong>Instructions</strong></p>
<p>Each question will only have one set of instructions so there is no need for a look up table but the instructions should be stored separately from the questions as mentioned previously so the table would look something like this;</p>
<ul>
<li>Q_Instructions
<ul>
<li>ID: int(4)</li>
<li>IText: text</li>
</ul>
</li>
</ul>
<p><strong>Relationships</strong></p>
<p>I haven&#8217;t mentioned relationships in depth in this post or the other tables of the database because I&#8217;m trying to keep each post simple and focused on one topic. I&#8217;ll go into more detail about the other tables of the database such as those dealing with multiple users and user specific tests in another post.</p>
]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve done quite a bit of work on the project (see the progress page) but I wasn&#8217;t sure what to document first because the application is going to store all the information in a MySQL database I thought I&#8217;d talk about the structure of the base (or most important) tables.</p>
<p><span id="more-9"></span><strong>Questions</strong></p>
<p>The application is going to revolve around questions so there obviously needs to be a table to store some of the details of each question. Each question will need an ID it will have some question text, it will also have a correct answer.</p>
<p><span id="more-9"></span></p>
<p>The answers are stored in another table so the question table will hold an identifier that relates to the correct answer instead of the correct answer itself. This is because the same answer may be used more than once (TRUE / FALSE for example) and referencing the answers instead of replicating them will save space.</p>
<p>Some question types are complicated so there will also be instructions to go with the question so the person knows what is expected of them.  Again these will be repeated several times and so stored in another table.</p>
<p>So the Question table would look something like;</p>
<ul>
<li>Q_Questions
<ul>
<li>ID: int(4)</li>
</ul>
<ul>
<li>QText: text</li>
</ul>
<ul>
<li>CorrectAnswer: int(4)</li>
</ul>
<ul>
<li>Instructions: int(4)</li>
</ul>
</li>
</ul>
<p><strong>Answers</strong></p>
<p>The answers table is much simpler seen as it only needs to store the actual answer and its ID.</p>
<ul>
<li>Q_Answers
<ul>
<li>ID: int(4)</li>
<li>AText: text</li>
</ul>
</li>
</ul>
<p><strong>Lookup Table</strong></p>
<p>A question may have more than one answer and an answer may be suggested for more than one question. This is modeled using a look up table is used. The look up table is a table that records which answers appear with which questions. This is achieved with two one-to-many relationships. The look up table has two fields&#8230;</p>
<ul>
<li>Q_QAL
<ul>
<li>QID: int(4)</li>
<li>AID: int(4)</li>
</ul>
</li>
</ul>
<p>&#8230;one that refers to the ID of the question and another that refers to the ID of the answer. Both fields are assigned as the primary key, this ensures that there are no duplicate entries. Whenever you want to associate an answer with a particular question you create a record in this table with the respective IDs. This way you can have as many or few answers associated with a question.</p>
<p><strong>Instructions</strong></p>
<p>Each question will only have one set of instructions so there is no need for a look up table but the instructions should be stored separately from the questions as mentioned previously so the table would look something like this;</p>
<ul>
<li>Q_Instructions
<ul>
<li>ID: int(4)</li>
<li>IText: text</li>
</ul>
</li>
</ul>
<p><strong>Relationships</strong></p>
<p>I haven&#8217;t mentioned relationships in depth in this post or the other tables of the database because I&#8217;m trying to keep each post simple and focused on one topic. I&#8217;ll go into more detail about the other tables of the database such as those dealing with multiple users and user specific tests in another post.</p>
]]></content:encoded>
			<wfw:commentRss>http://klkl.co.uk/2007/11/21/thoughts-on-database-structure/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>XML Document Type Definition</title>
		<link>http://klkl.co.uk/2007/11/06/xml-document-type-definition/</link>
		<comments>http://klkl.co.uk/2007/11/06/xml-document-type-definition/#comments</comments>
		<pubDate>Tue, 06 Nov 2007 13:07:44 +0000</pubDate>
		<dc:creator>klkl</dc:creator>
				<category><![CDATA[Kquestion]]></category>

		<guid isPermaLink="false">http://klkl.co.uk/?p=23</guid>
		<description><![CDATA[<style type="text/css"> pre { border: 1pt dashed black; padding: 1em 1em; font-size: 9pt; background : #DDFFDD; color : black; white-space: pre-wrap; } pre.q { border: 1pt dashed black; padding: 1em 1em; font-size: 9pt; background : #FFC1C1; color : black;word-wrap: break-word; white-space: pre-wrap;} pre.d { border: 1pt dashed black; padding: 1em 1em; font-size: 9pt; background : #C6D4F7; color : black;word-wrap: break-word; white-space: pre-wrap;} </style>
<p>This is the XML document type definition I&#8217;ve come up with for the KQuestion project. The latest version will also be available at (<a href="http://klkl.co.uk/Kquestion/kquestion.dtd" title="kquestion.dtd">klkl.co.uk/Kquestion/kquestion.dtd</a>). Note: Although its not clear on this page (because of word wrapping) normally everything between each pair of &lt; &amp; &gt; is on one line but it is clear in the above link.</p>
<p><span id="more-23"></span><br />
<span id="more-12"></span><strong>KQuestion.dtd</strong></p>
<pre class="d">&lt;!ELEMENT QUESTIONBLOCK (SINGLEQUESTIONS|COMMONANSWERS|
MULTIPLESTATEMENTS|ORDEREDQUESTIONS)+&gt;
&lt;!ELEMENT ORDEREDQUESTIONS (SINGLEQUESTIONS|
COMMONANSWERS|MULTIPLESTATEMENTS)+&gt;
&lt;!ELEMENT SINGLEQUESTIONS (INSTRUCTIONS,(QUESTION)+)&gt;
&lt;!ELEMENT COMMONANSWERS (INSTRUCTIONS,ANSWERS,(QUESTION)+)&gt;
&lt;!ELEMENT MULTIPLESTATEMENTS (INSTRUCTIONS,ANSWERS,(QUESTION)+)&gt;
&lt;!ELEMENT INSTRUCTIONS (#PCDATA)&gt;
&lt;!ELEMENT QUESTION (TEXT,SCORE,CORRECTANSWER,(ANSWERS|STATEMENTS)?)&gt;
&lt;!ATTLIST QUESTION ORDER ID #IMPLIED&gt;
&lt;!ELEMENT TEXT (#PCDATA)&gt;
&lt;!ELEMENT SCORE (#PCDATA)&gt;
&lt;!ELEMENT CORRECTANSWER (#PCDATA)&gt;
&lt;!ELEMENT ANSWERS (ANSWER)+&gt;
&lt;!ELEMENT ANSWER (#PCDATA)&gt;
&lt;!ATTLIST ANSWER NUMBER ID #REQUIRED&gt;
&lt;!ELEMENT STATEMENTS (STATMENT)+&gt;
&lt;!ELEMENT STATEMENT (#PCDATA)&gt;
&lt;!ATTLIST STATEMENT NUMBER ID #REQUIRED&gt;</pre>
<p>There is very good documentation on document type definitions at W3C (<a href="http://www.w3schools.com/dtd/default.asp" title="W3C document type definition tutorial">http://www.w3schools.com/dtd/default.asp</a>) you should read that if you want to know more.</p>
]]></description>
			<content:encoded><![CDATA[<style type="text/css"> pre { border: 1pt dashed black; padding: 1em 1em; font-size: 9pt; background : #DDFFDD; color : black; white-space: pre-wrap; } pre.q { border: 1pt dashed black; padding: 1em 1em; font-size: 9pt; background : #FFC1C1; color : black;word-wrap: break-word; white-space: pre-wrap;} pre.d { border: 1pt dashed black; padding: 1em 1em; font-size: 9pt; background : #C6D4F7; color : black;word-wrap: break-word; white-space: pre-wrap;} </style>
<p>This is the XML document type definition I&#8217;ve come up with for the KQuestion project. The latest version will also be available at (<a href="http://klkl.co.uk/Kquestion/kquestion.dtd" title="kquestion.dtd">klkl.co.uk/Kquestion/kquestion.dtd</a>). Note: Although its not clear on this page (because of word wrapping) normally everything between each pair of &lt; &amp; &gt; is on one line but it is clear in the above link.</p>
<p><span id="more-23"></span><br />
<span id="more-12"></span><strong>KQuestion.dtd</strong></p>
<pre class="d">&lt;!ELEMENT QUESTIONBLOCK (SINGLEQUESTIONS|COMMONANSWERS|
MULTIPLESTATEMENTS|ORDEREDQUESTIONS)+&gt;
&lt;!ELEMENT ORDEREDQUESTIONS (SINGLEQUESTIONS|
COMMONANSWERS|MULTIPLESTATEMENTS)+&gt;
&lt;!ELEMENT SINGLEQUESTIONS (INSTRUCTIONS,(QUESTION)+)&gt;
&lt;!ELEMENT COMMONANSWERS (INSTRUCTIONS,ANSWERS,(QUESTION)+)&gt;
&lt;!ELEMENT MULTIPLESTATEMENTS (INSTRUCTIONS,ANSWERS,(QUESTION)+)&gt;
&lt;!ELEMENT INSTRUCTIONS (#PCDATA)&gt;
&lt;!ELEMENT QUESTION (TEXT,SCORE,CORRECTANSWER,(ANSWERS|STATEMENTS)?)&gt;
&lt;!ATTLIST QUESTION ORDER ID #IMPLIED&gt;
&lt;!ELEMENT TEXT (#PCDATA)&gt;
&lt;!ELEMENT SCORE (#PCDATA)&gt;
&lt;!ELEMENT CORRECTANSWER (#PCDATA)&gt;
&lt;!ELEMENT ANSWERS (ANSWER)+&gt;
&lt;!ELEMENT ANSWER (#PCDATA)&gt;
&lt;!ATTLIST ANSWER NUMBER ID #REQUIRED&gt;
&lt;!ELEMENT STATEMENTS (STATMENT)+&gt;
&lt;!ELEMENT STATEMENT (#PCDATA)&gt;
&lt;!ATTLIST STATEMENT NUMBER ID #REQUIRED&gt;</pre>
<p>There is very good documentation on document type definitions at W3C (<a href="http://www.w3schools.com/dtd/default.asp" title="W3C document type definition tutorial">http://www.w3schools.com/dtd/default.asp</a>) you should read that if you want to know more.</p>
]]></content:encoded>
			<wfw:commentRss>http://klkl.co.uk/2007/11/06/xml-document-type-definition/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Parse an XML File Using PHP: Part 1</title>
		<link>http://klkl.co.uk/2007/10/23/how-to-parse-an-xml-file-using-php-part-1/</link>
		<comments>http://klkl.co.uk/2007/10/23/how-to-parse-an-xml-file-using-php-part-1/#comments</comments>
		<pubDate>Tue, 23 Oct 2007 12:33:01 +0000</pubDate>
		<dc:creator>klkl</dc:creator>
				<category><![CDATA[Kquestion]]></category>

		<guid isPermaLink="false">http://klkl.co.uk/?p=5</guid>
		<description><![CDATA[<style type="text/css"> pre { border: 1pt dashed black; padding: 1em 1em; font-size: 9pt; background : #DDFFDD; color : black; white-space: pre-wrap; } pre.q { border: 1pt dashed black; padding: 1em 1em; font-size: 9pt; background : #FFC1C1; color : black;word-wrap: break-word; white-space: pre-wrap;} pre.d { border: 1pt dashed black; padding: 1em 1em; font-size: 9pt; background : #C6D4F7; color : black;word-wrap: break-word; white-space: pre-wrap;} pre.p { border: 1pt dashed black; padding: 1em 1em; font-size: 9pt; background : #FFFF96; color : black;word-wrap: break-word; white-space: pre-wrap;} </style>
<p>This post follows the multiple choice question theme. I&#8217;ve spent quite a bit of time working on how to go about parsing an XML file using PHP. I had to pay particular attention to the structure of the XML file with reference to which elements appeared where and which were repeated but in different orders throughout the document.</p>
<p>I&#8217;m the sort who likes to learn by doing and having a play with things. I read a basic php xml parsing tutorial on sitepoint written by Kevin Yank (<a href="http://www.sitepoint.com/article/php-xml-parsing-rss-1-0" title="PHP and XML: Parsing RSS 1.0">PHP and XML: Parsing RSS 1.0</a>) it explains the process pretty well so if you want to know the specifics of creating the parser object I recommend you read that brief tutorial or consult the php manual.</p>
<p><span id="more-5"></span></p>
<p>When using PHPs built in XML parser there are three functions that are required:</p>
<ul>
<li>An element opening function which is called whenever the parser encounters an opening element.</li>
<li>A data function which is called whenever some data between elements is encountered.</li>
<li>An element closing function which is called whenever the parser encounters a closing element.</li>
</ul>
<p><strong>The openElement function</strong></p>
<pre class="p">function openElement($parser, $tagName, $attrs) {
  global $SQ, $CA, $MS, $Q, $A, $answercount, $ANo, $tag;
  $tag = $tagName;  if (!$SQ || !$CA || !$Q || !$A) {
  	switch ($tagName) {
  	case "SINGLEQUESTIONS":
  		$SQ = true;
  	break;
  	case "COMMONANSWERS":
  		$CA = true;
  	break;
  	case "MULTIPLESTATEMENTS":
  		$MS = true;
  	break;
  	case "QUESTION":
  		$Q = true;
  	break;
  	case "ANSWERS":
  		$A = true;
  	break;
  	}
  }  if ($A) {
  	if ($tagName == "ANSWER") {
  		$ANo[$answercount] = $attrs['NUMBER'];
  	}
  }
}</pre>
<p>The function takes three arguments ($parser, $tagName, $attrs)</p>
<ul>
<li><strong>$parser</strong> is a reference to the parser being used to parse the document.</li>
<li><strong>$tagName</strong> is  the name of the element that triggered the function (It is always returned as ALL UPPERCASE).</li>
<li><strong>$attrs</strong> is an array of the attributes that the element had e.g. if the element was &lt;answer number=&#8221;3&#8243;&gt; then the value of $attrs[&#8217;NUMBER&#8217;] would be &#8220;3&#8243;. (notice the case is always uppercase for attributes too).</li>
</ul>
<p>The global statement at the top of the function is important to make sure that any variables the function manipulates will be available to the other functions.</p>
<p>The $SQ, $CA, $Q, $A variables have been used as boolean flags in my implementation to represent whether or not the parser is within specific elements. The switch statement checks to see if the element responsible for triggering the function ($tagName) is one of the elements being monitored and then sets the corresponding flag variable to true.</p>
<p>The flag variables are required because the same elements do not always appear in the same order in the document type definition so it is important to know which elements the parser is in when dealing with the information it will later glean. The <strong>$tag </strong>variable represents the last element that<br />
triggered the function.</p>
<p>You can see that the $A variable is used to track whether or not the parser is within an answers element. The answers element contains answer elements (See <a href="http://klkl.co.uk/?p=4" title="Multiple Choice Questions XML">MCQ XML</a>). The last bit of the function stores the &#8216;number&#8217; attribute of each answer element in an array I&#8217;ve called<strong> $ANo</strong> this is because the CORRECTANSWER element is a relative reference to the number attribute of the answer elements.</p>
<p>Once the answers are put into the database the relative values in the array will be replaced with unique identifiers from the database.</p>
<p>I&#8217;ll comment on the other multiple choice question XML parsing specific functions in other posts.</p>
]]></description>
			<content:encoded><![CDATA[<style type="text/css"> pre { border: 1pt dashed black; padding: 1em 1em; font-size: 9pt; background : #DDFFDD; color : black; white-space: pre-wrap; } pre.q { border: 1pt dashed black; padding: 1em 1em; font-size: 9pt; background : #FFC1C1; color : black;word-wrap: break-word; white-space: pre-wrap;} pre.d { border: 1pt dashed black; padding: 1em 1em; font-size: 9pt; background : #C6D4F7; color : black;word-wrap: break-word; white-space: pre-wrap;} pre.p { border: 1pt dashed black; padding: 1em 1em; font-size: 9pt; background : #FFFF96; color : black;word-wrap: break-word; white-space: pre-wrap;} </style>
<p>This post follows the multiple choice question theme. I&#8217;ve spent quite a bit of time working on how to go about parsing an XML file using PHP. I had to pay particular attention to the structure of the XML file with reference to which elements appeared where and which were repeated but in different orders throughout the document.</p>
<p>I&#8217;m the sort who likes to learn by doing and having a play with things. I read a basic php xml parsing tutorial on sitepoint written by Kevin Yank (<a href="http://www.sitepoint.com/article/php-xml-parsing-rss-1-0" title="PHP and XML: Parsing RSS 1.0">PHP and XML: Parsing RSS 1.0</a>) it explains the process pretty well so if you want to know the specifics of creating the parser object I recommend you read that brief tutorial or consult the php manual.</p>
<p><span id="more-5"></span></p>
<p>When using PHPs built in XML parser there are three functions that are required:</p>
<ul>
<li>An element opening function which is called whenever the parser encounters an opening element.</li>
<li>A data function which is called whenever some data between elements is encountered.</li>
<li>An element closing function which is called whenever the parser encounters a closing element.</li>
</ul>
<p><strong>The openElement function</strong></p>
<pre class="p">function openElement($parser, $tagName, $attrs) {
  global $SQ, $CA, $MS, $Q, $A, $answercount, $ANo, $tag;
  $tag = $tagName;  if (!$SQ || !$CA || !$Q || !$A) {
  	switch ($tagName) {
  	case "SINGLEQUESTIONS":
  		$SQ = true;
  	break;
  	case "COMMONANSWERS":
  		$CA = true;
  	break;
  	case "MULTIPLESTATEMENTS":
  		$MS = true;
  	break;
  	case "QUESTION":
  		$Q = true;
  	break;
  	case "ANSWERS":
  		$A = true;
  	break;
  	}
  }  if ($A) {
  	if ($tagName == "ANSWER") {
  		$ANo[$answercount] = $attrs['NUMBER'];
  	}
  }
}</pre>
<p>The function takes three arguments ($parser, $tagName, $attrs)</p>
<ul>
<li><strong>$parser</strong> is a reference to the parser being used to parse the document.</li>
<li><strong>$tagName</strong> is  the name of the element that triggered the function (It is always returned as ALL UPPERCASE).</li>
<li><strong>$attrs</strong> is an array of the attributes that the element had e.g. if the element was &lt;answer number=&#8221;3&#8243;&gt; then the value of $attrs[&#8217;NUMBER&#8217;] would be &#8220;3&#8243;. (notice the case is always uppercase for attributes too).</li>
</ul>
<p>The global statement at the top of the function is important to make sure that any variables the function manipulates will be available to the other functions.</p>
<p>The $SQ, $CA, $Q, $A variables have been used as boolean flags in my implementation to represent whether or not the parser is within specific elements. The switch statement checks to see if the element responsible for triggering the function ($tagName) is one of the elements being monitored and then sets the corresponding flag variable to true.</p>
<p>The flag variables are required because the same elements do not always appear in the same order in the document type definition so it is important to know which elements the parser is in when dealing with the information it will later glean. The <strong>$tag </strong>variable represents the last element that<br />
triggered the function.</p>
<p>You can see that the $A variable is used to track whether or not the parser is within an answers element. The answers element contains answer elements (See <a href="http://klkl.co.uk/?p=4" title="Multiple Choice Questions XML">MCQ XML</a>). The last bit of the function stores the &#8216;number&#8217; attribute of each answer element in an array I&#8217;ve called<strong> $ANo</strong> this is because the CORRECTANSWER element is a relative reference to the number attribute of the answer elements.</p>
<p>Once the answers are put into the database the relative values in the array will be replaced with unique identifiers from the database.</p>
<p>I&#8217;ll comment on the other multiple choice question XML parsing specific functions in other posts.</p>
]]></content:encoded>
			<wfw:commentRss>http://klkl.co.uk/2007/10/23/how-to-parse-an-xml-file-using-php-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Multiple Choice Question Formats</title>
		<link>http://klkl.co.uk/2007/10/09/multiple-choice-question-formats/</link>
		<comments>http://klkl.co.uk/2007/10/09/multiple-choice-question-formats/#comments</comments>
		<pubDate>Tue, 09 Oct 2007 12:54:33 +0000</pubDate>
		<dc:creator>klkl</dc:creator>
				<category><![CDATA[Kquestion]]></category>

		<guid isPermaLink="false">http://klkl.co.uk/?p=3</guid>
		<description><![CDATA[<style type="text/css">pre.q { border: 1pt dashed black; padding: 1em 1em; font-size: 8pt; background : #FFC1C1; color : black; white-space: pre-wrap; word-wrap: break-word;}</style>
<p>One of my objectives for Kquestion is for it to be able to parse and generate an XML of multiple choice questions. That’s because I think typing the questions into a template will be a lot quicker than using the application, however, both methods should be available. I’m going talk about the different formats of multiple choice question and then in another post how I’ve implemented them in XML and then talk about the document type definition created for the format.</p>
<p><strong>Isolated single questions</strong></p>
<p>This type of question consists of question text and a list of possible answers. They are isolated in that the question and the answers are used only once.</p>
<p><span id="more-3"></span></p>
<pre class="q">Question: One plus Two equals:
Answer 1: 5
Answer 2: 3
Answer 3: 1
Answer 4: 2
Answer 5: 4</pre>
<p><strong>Common answer questions</strong><br/>Questions of this type share a common list of answers.</p>
<pre class="q">Question: What is the colour of grass?
Question: What colour is blood?
Question: What is the colour of a tangerine?             

Answer 1: Red
Answer 2: Orange
Answer 3: Yellow
Answer 4: Green
Answer 5: Blue</pre>
<p><strong>Questions with multiple statements</strong></p>
<p>Questions of this type consist of multiple statements and the student must determine which statements are true and which are false then choose the answer from a list of answers.</p>
<pre class="q">Question: When you get a headache;
1. You should consider taking paracetamol.
2. It would be sensible to avoid sources of loud noise.
3. You will need to make an appointment with your doctor to have a hole
   drilled into your head to relieve the pressure.     

Answer 1: If 1, 2 and 3 are correct.
Answer 2: If 1 and 2 only are correct.
Answer 3: If 2 and 3 only are correct.
Answer 4: If 1 only is correct.
Answer 5: If 3 only is correct.</pre>
<p>There are other, more advanced, multiple choice question formats that I’ve not mentioned here but I’ll cover those at some point in the future.</p>
<p>next time… The XML.</p>
]]></description>
			<content:encoded><![CDATA[<style type="text/css">pre.q { border: 1pt dashed black; padding: 1em 1em; font-size: 8pt; background : #FFC1C1; color : black; white-space: pre-wrap; word-wrap: break-word;}</style>
<p>One of my objectives for Kquestion is for it to be able to parse and generate an XML of multiple choice questions. That’s because I think typing the questions into a template will be a lot quicker than using the application, however, both methods should be available. I’m going talk about the different formats of multiple choice question and then in another post how I’ve implemented them in XML and then talk about the document type definition created for the format.</p>
<p><strong>Isolated single questions</strong></p>
<p>This type of question consists of question text and a list of possible answers. They are isolated in that the question and the answers are used only once.</p>
<p><span id="more-3"></span></p>
<pre class="q">Question: One plus Two equals:
Answer 1: 5
Answer 2: 3
Answer 3: 1
Answer 4: 2
Answer 5: 4</pre>
<p><strong>Common answer questions</strong><br/>Questions of this type share a common list of answers.</p>
<pre class="q">Question: What is the colour of grass?
Question: What colour is blood?
Question: What is the colour of a tangerine?             

Answer 1: Red
Answer 2: Orange
Answer 3: Yellow
Answer 4: Green
Answer 5: Blue</pre>
<p><strong>Questions with multiple statements</strong></p>
<p>Questions of this type consist of multiple statements and the student must determine which statements are true and which are false then choose the answer from a list of answers.</p>
<pre class="q">Question: When you get a headache;
1. You should consider taking paracetamol.
2. It would be sensible to avoid sources of loud noise.
3. You will need to make an appointment with your doctor to have a hole
   drilled into your head to relieve the pressure.     

Answer 1: If 1, 2 and 3 are correct.
Answer 2: If 1 and 2 only are correct.
Answer 3: If 2 and 3 only are correct.
Answer 4: If 1 only is correct.
Answer 5: If 3 only is correct.</pre>
<p>There are other, more advanced, multiple choice question formats that I’ve not mentioned here but I’ll cover those at some point in the future.</p>
<p>next time… The XML.</p>
]]></content:encoded>
			<wfw:commentRss>http://klkl.co.uk/2007/10/09/multiple-choice-question-formats/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Multiple Choice Questions &amp; XML</title>
		<link>http://klkl.co.uk/2007/10/09/multiple-choice-questions-xml/</link>
		<comments>http://klkl.co.uk/2007/10/09/multiple-choice-questions-xml/#comments</comments>
		<pubDate>Tue, 09 Oct 2007 12:51:28 +0000</pubDate>
		<dc:creator>klkl</dc:creator>
				<category><![CDATA[Kquestion]]></category>

		<guid isPermaLink="false">http://klkl.co.uk/?p=19</guid>
		<description><![CDATA[<style type="text/css">pre { border: 1pt dashed black; padding: 1em 1em; font-size: 8pt; background : #DDFFDD; color : black; white-space: pre-wrap; } pre.q { border: 1pt dashed black; padding: 1em 1em; font-size: 8pt; background : #FFC1C1; color : black;word-wrap: break-word; white-space: pre-wrap;}</style>
<p>XML is used to store Information about something in a logical format. Information is data that has meaning and that meaning can be represented in XML via its structure. A well written XML schema should be easy to understand and follow. Data should be stored within elements (sometimes referred to as tags) whereas information about the data (metadata) should be stored in attributes.</p>
<p>Below is the XML structure I devised to contain the information about the different questions types discussed in my ‘<a title="Multiple Choice Question Formats" href="http://klkl.co.uk/2007/10/multiple-choice-question-formats/">Multiple Choice Question Formats</a>‘ post. I will refer to the element that contains the different question types as the question type element but in reality the name of the question type element will change depending on the question type.</p>
<p><span id="more-19"></span>
<p><strong>Single Questions</strong></p>
<pre>&lt;SINGLEQUESTIONS&gt;
 &lt;INSTRUCTIONS&gt;&lt;/INSTRUCTIONS&gt;
 &lt;QUESTION&gt;
  &lt;TEXT&gt;&lt;/TEXT&gt;
  &lt;SCORE&gt;&lt;/SCORE&gt;
  &lt;CORRECTANSWER&gt;&lt;/CORRECTANSWER&gt;
  &lt;ANSWERS&gt;
   &lt;ANSWER NUMBER="1"&gt;&lt;/ANSWER&gt;
   &lt;ANSWER NUMBER="2"&gt;&lt;/ANSWER&gt;
   &lt;ANSWER NUMBER="3"&gt;&lt;/ANSWER&gt;
  &lt;/ANSWERS&gt;
 &lt;/QUESTION&gt;
&lt;/SINGLEQUESTIONS&gt;</pre>
</p>
<ul>
<li>The SINGLEQUESTIONS element contains all the questions of this type.</li>
<li>The INSTRUCTIONS element is used to instruct the student how to answer the question.</li>
<li>The QUESTION element contains all the relevant information for one question. More than one of these elements can reside within the SINGLEQUESTIONS element.</li>
<li>The TEXT element contains the question text.</li>
<li>The SCORE element contains the score obtained for answering the question correctly.</li>
<li>The CORRECTANSWER element obviously contains the correct answer</li>
<li>The ANSWERS element contains the ANSWER elements</li>
<li>The ANSWER element has a NUMBER attribute to distinguish it from the other ANSWER elements and contains the answer text.</li>
</ul>
<p><strong>Common Answers</strong></p>
<pre>&lt;COMMONANSWERS&gt;
 &lt;INSTRUCTIONS&gt;&lt;/INSTRUCTIONS&gt;
 &lt;ANSWERS&gt;
  &lt;ANSWER NUMBER="1"&gt;&lt;/ANSWER&gt;
  &lt;ANSWER NUMBER="2"&gt;&lt;/ANSWER&gt;
  &lt;ANSWER NUMBER="3"&gt;&lt;/ANSWER&gt;
 &lt;/ANSWERS&gt;
 &lt;QUESTION&gt;
  &lt;TEXT&gt;&lt;/TEXT&gt;
  &lt;SCORE&gt;&lt;/SCORE&gt;
  &lt;CORRECTANSWER&gt;&lt;/CORRECTANSWER&gt;
 &lt;/QUESTION&gt;
&lt;/COMMONANSWERS&gt;</pre>
</p>
<p>The elements in this example all have the same meaning as in the first example. The difference is that they are ordered differently. In the first example all the question and answer information was contained within the QUESTION element. Now because the answer set is common to all of the questions within the COMMONANSWER element is has been removed from the QUESTION element and is only listed once.</p>
<p>The application will understand that all questions within a COMMONANSWER element will refer to those answers. This grouping helps to prevent repetitive data being stored. If a separate group of questions all refered to a common set of answers then these would be listed in the same format as this but within a new COMMONANSWER element.</p>
<p><strong>Multiple Statements</strong></p>
<pre>&lt;MULTIPLESTATEMENTS&gt;
 &lt;INSTRUCTIONS&gt;&lt;/INSTRUCTIONS&gt;
 &lt;ANSWERS&gt;
  &lt;ANSWER NUMBER="1"&gt;&lt;/ANSWER&gt;
  &lt;ANSWER NUMBER="2"&gt;&lt;/ANSWER&gt;
  &lt;ANSWER NUMBER="3"&gt;&lt;/ANSWER&gt;
 &lt;/ANSWERS&gt;
 &lt;QUESTION&gt;
  &lt;TEXT&gt;&lt;/TEXT&gt;
  &lt;SCORE&gt;&lt;/SCORE&gt;
  &lt;CORRECTANSWER&gt;&lt;/CORRECTANSWER&gt;
  &lt;STATEMENTS&gt;
   &lt;STATEMENT NUMBER="1"&gt;&lt;/STATEMENT&gt;
   &lt;STATEMENT NUMBER="2"&gt;&lt;/STATEMENT&gt;
   &lt;STATEMENT NUMBER="3"&gt;&lt;/STATEMENT&gt;
  &lt;/STATEMENTS&gt;
 &lt;/QUESTION&gt;
&lt;/MULTIPLESTATEMENTS&gt;</pre>
</p>
<p>The MULTIPLESTATEMENTS question is almost the same as the common answers format. The difference is that each question has a set of statements which the student evaluates as true or false and then chooses the correct answer.</p>
<p><strong>True || False &amp;&amp; Because Of?</strong></p>
<p>Another type of question I refer to as ‘true false because of’ consists of two statements which the user must decide if they each true or false. Then the student must decide if the second statement is the reason for the first.</p>
<p>I have decided to include this type of question in the COMMONANSWERS question type because all of the questions refer to the same set of answers (see below). Due to the design of the COMMONANSWERS element both statements must reside in one block of text (see the above example). The two statements can be distinguised by using paragraph, &lt;p&gt; html elements.</p>
<p>
<pre class="q">Question:
The day is split into a light part and a dark part.
The earth rotates as it revolves around the sun.

Answer 1: Both statments are true and the second statement is a correct
          explanation for the first.
Answer 2: Both statments are true and the second statement is NOT a
          correct explanation for the first.
Answer 3: Only the first statement is true.
Answer 4: Only the second statement is true.
Answer 5: Both statements are false.</pre></p>
]]></description>
			<content:encoded><![CDATA[<style type="text/css">pre { border: 1pt dashed black; padding: 1em 1em; font-size: 8pt; background : #DDFFDD; color : black; white-space: pre-wrap; } pre.q { border: 1pt dashed black; padding: 1em 1em; font-size: 8pt; background : #FFC1C1; color : black;word-wrap: break-word; white-space: pre-wrap;}</style>
<p>XML is used to store Information about something in a logical format. Information is data that has meaning and that meaning can be represented in XML via its structure. A well written XML schema should be easy to understand and follow. Data should be stored within elements (sometimes referred to as tags) whereas information about the data (metadata) should be stored in attributes.</p>
<p>Below is the XML structure I devised to contain the information about the different questions types discussed in my ‘<a title="Multiple Choice Question Formats" href="http://klkl.co.uk/2007/10/multiple-choice-question-formats/">Multiple Choice Question Formats</a>‘ post. I will refer to the element that contains the different question types as the question type element but in reality the name of the question type element will change depending on the question type.</p>
<p><span id="more-19"></span>
<p><strong>Single Questions</strong></p>
<pre>&lt;SINGLEQUESTIONS&gt;
 &lt;INSTRUCTIONS&gt;&lt;/INSTRUCTIONS&gt;
 &lt;QUESTION&gt;
  &lt;TEXT&gt;&lt;/TEXT&gt;
  &lt;SCORE&gt;&lt;/SCORE&gt;
  &lt;CORRECTANSWER&gt;&lt;/CORRECTANSWER&gt;
  &lt;ANSWERS&gt;
   &lt;ANSWER NUMBER="1"&gt;&lt;/ANSWER&gt;
   &lt;ANSWER NUMBER="2"&gt;&lt;/ANSWER&gt;
   &lt;ANSWER NUMBER="3"&gt;&lt;/ANSWER&gt;
  &lt;/ANSWERS&gt;
 &lt;/QUESTION&gt;
&lt;/SINGLEQUESTIONS&gt;</pre>
</p>
<ul>
<li>The SINGLEQUESTIONS element contains all the questions of this type.</li>
<li>The INSTRUCTIONS element is used to instruct the student how to answer the question.</li>
<li>The QUESTION element contains all the relevant information for one question. More than one of these elements can reside within the SINGLEQUESTIONS element.</li>
<li>The TEXT element contains the question text.</li>
<li>The SCORE element contains the score obtained for answering the question correctly.</li>
<li>The CORRECTANSWER element obviously contains the correct answer</li>
<li>The ANSWERS element contains the ANSWER elements</li>
<li>The ANSWER element has a NUMBER attribute to distinguish it from the other ANSWER elements and contains the answer text.</li>
</ul>
<p><strong>Common Answers</strong></p>
<pre>&lt;COMMONANSWERS&gt;
 &lt;INSTRUCTIONS&gt;&lt;/INSTRUCTIONS&gt;
 &lt;ANSWERS&gt;
  &lt;ANSWER NUMBER="1"&gt;&lt;/ANSWER&gt;
  &lt;ANSWER NUMBER="2"&gt;&lt;/ANSWER&gt;
  &lt;ANSWER NUMBER="3"&gt;&lt;/ANSWER&gt;
 &lt;/ANSWERS&gt;
 &lt;QUESTION&gt;
  &lt;TEXT&gt;&lt;/TEXT&gt;
  &lt;SCORE&gt;&lt;/SCORE&gt;
  &lt;CORRECTANSWER&gt;&lt;/CORRECTANSWER&gt;
 &lt;/QUESTION&gt;
&lt;/COMMONANSWERS&gt;</pre>
</p>
<p>The elements in this example all have the same meaning as in the first example. The difference is that they are ordered differently. In the first example all the question and answer information was contained within the QUESTION element. Now because the answer set is common to all of the questions within the COMMONANSWER element is has been removed from the QUESTION element and is only listed once.</p>
<p>The application will understand that all questions within a COMMONANSWER element will refer to those answers. This grouping helps to prevent repetitive data being stored. If a separate group of questions all refered to a common set of answers then these would be listed in the same format as this but within a new COMMONANSWER element.</p>
<p><strong>Multiple Statements</strong></p>
<pre>&lt;MULTIPLESTATEMENTS&gt;
 &lt;INSTRUCTIONS&gt;&lt;/INSTRUCTIONS&gt;
 &lt;ANSWERS&gt;
  &lt;ANSWER NUMBER="1"&gt;&lt;/ANSWER&gt;
  &lt;ANSWER NUMBER="2"&gt;&lt;/ANSWER&gt;
  &lt;ANSWER NUMBER="3"&gt;&lt;/ANSWER&gt;
 &lt;/ANSWERS&gt;
 &lt;QUESTION&gt;
  &lt;TEXT&gt;&lt;/TEXT&gt;
  &lt;SCORE&gt;&lt;/SCORE&gt;
  &lt;CORRECTANSWER&gt;&lt;/CORRECTANSWER&gt;
  &lt;STATEMENTS&gt;
   &lt;STATEMENT NUMBER="1"&gt;&lt;/STATEMENT&gt;
   &lt;STATEMENT NUMBER="2"&gt;&lt;/STATEMENT&gt;
   &lt;STATEMENT NUMBER="3"&gt;&lt;/STATEMENT&gt;
  &lt;/STATEMENTS&gt;
 &lt;/QUESTION&gt;
&lt;/MULTIPLESTATEMENTS&gt;</pre>
</p>
<p>The MULTIPLESTATEMENTS question is almost the same as the common answers format. The difference is that each question has a set of statements which the student evaluates as true or false and then chooses the correct answer.</p>
<p><strong>True || False &amp;&amp; Because Of?</strong></p>
<p>Another type of question I refer to as ‘true false because of’ consists of two statements which the user must decide if they each true or false. Then the student must decide if the second statement is the reason for the first.</p>
<p>I have decided to include this type of question in the COMMONANSWERS question type because all of the questions refer to the same set of answers (see below). Due to the design of the COMMONANSWERS element both statements must reside in one block of text (see the above example). The two statements can be distinguised by using paragraph, &lt;p&gt; html elements.</p>
<p>
<pre class="q">Question:
The day is split into a light part and a dark part.
The earth rotates as it revolves around the sun.

Answer 1: Both statments are true and the second statement is a correct
          explanation for the first.
Answer 2: Both statments are true and the second statement is NOT a
          correct explanation for the first.
Answer 3: Only the first statement is true.
Answer 4: Only the second statement is true.
Answer 5: Both statements are false.</pre></p>
]]></content:encoded>
			<wfw:commentRss>http://klkl.co.uk/2007/10/09/multiple-choice-questions-xml/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Kquestion Begins</title>
		<link>http://klkl.co.uk/2007/10/07/kquestion-begins/</link>
		<comments>http://klkl.co.uk/2007/10/07/kquestion-begins/#comments</comments>
		<pubDate>Sun, 07 Oct 2007 12:55:59 +0000</pubDate>
		<dc:creator>klkl</dc:creator>
				<category><![CDATA[Kquestion]]></category>

		<guid isPermaLink="false">http://klkl.co.uk/?p=1</guid>
		<description><![CDATA[<p>Currently a friend and I are developing a php based multiple choice question application that will hopefully help me and others study for exams etc. This blog will document the progress of and any thoughts about the project.</p>
]]></description>
			<content:encoded><![CDATA[<p>Currently a friend and I are developing a php based multiple choice question application that will hopefully help me and others study for exams etc. This blog will document the progress of and any thoughts about the project.</p>
]]></content:encoded>
			<wfw:commentRss>http://klkl.co.uk/2007/10/07/kquestion-begins/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

