1. KNOWLEDGE HUB
  2. Lambda Learn (Moodle & Totara)
  3. CONTENT MANAGEMENT: RESOURCES & ACTIVITIES

Question Types XML Format

The XML Format is a specific format for importing and exporting questions to be used with the Quiz module. 

NOTE  NOTE

A word about validity (and CDATA)

The XML parser assumes that the XML file is well formed and does not detect or report errors. If it is not you are very likely to get unexpected errors. If you are hand-coding the XML file it is strongly recommended that you pass it through some sort of XML verifier before importing into Lambda Learn. A simple way to do this is to open the XML file using Firefox or Internet Explorer.

Note particularly that embedded HTML fragments should be within CDATA sections. CDATA example:

<questiontext format="html">
<text><![CDATA[
Now I can include <strong>any</strong> HTML that I<br />
wish. Without the CDATA, the <i>HTML</i> tags would break
the XML!!
]]>
</text>
</questiontext>
 

Overall Structure of XML Files

The file is enclosed by tags as follows. It is important to make sure the xml tag only is really the first line of the file. A blank first line, or additional tags on the first line will confuse the XML parser.

<?xml version="1.0" ?>
<quiz>
.
.
.
</quiz>

Within the <quiz> tags are any number of <question> tags. One of these <question> tags can be a dummy question with a category type to specify a category for the import/export.

<question type="category">
<category>
<text>$course$/XXXX</text>
</category>
</question>
  • Where XXXX is the new category name. If the category exists, the question(s) will be added to the existing course; otherwise a new category will be created. This only works if you have "Get category from file" checked.

  • Multiple categories can be specified in the same file. Just add another dummy 'category' question each time you would like to establish a new category and the questions that follow it will be placed there.

  • The file must be encoded in UTF8

  • The XML import and export are balanced in functionality, so if you need to understand the format you can simply create some questions and export them to see what it looks like.

Back to TOPICS

 

Tags Common to All Question Types

A question is written as follows.

<question type="multichoice|truefalse|shortanswer|matching|cloze|essay|numerical|description">
<name>
<text>Name of question</text>
</name>
<questiontext format="html">
<text>What is the answer to this question?</text>
</questiontext>
.
.
.
</question>

Each question requires a <name> tag and <question-text> tag for the XML file to import into the LMS properly.

"Format" selects the Formatting options for the question text.  The choice effects the way in which the text will be displayed. The options are:

  •  html (the default)
  • plain_text
  • markdown 

Further tags, which usually include at least one <answer> tag, follow in the space marked with dots as child nodes to the <question> tag. The response-related tags are listed further down on this page. Various (optional?) tags are possible.

  • tags (non-hierarchical keywords)
  • penalty
  • generalfeedback
  • defaultgrade
  • hidden

Even though question tags (non-hierarchical keywords) are not fully supported in the question engine, they can be imported and exported via XML.

<question ...>
...
<tags>
<tag>
<text>keyword1</text>
</tag>
<tag>
<text>keyword2</text>
</tag>
...
</tags>
...
</question>

The <image> tag contains the url of any included image. Nested within the <image> tag may be an <image_base64> tag which contains the actual image data encoded in base64 [1].

Back to TOPICS

 

Question Types

In the following question type examples the common parts of the question are not shown to improve clarity. It's a good idea to export some examples yourself to see a full example.

Question Type

moodleM2 totara icon

Multiple Choice

Allows the selection of a single or multiple responses from a pre-defined list. The total grade must add up to 100%. If a single answer is correct, one answer must have the grade set to 100%.

orange check mark green check mark

True/False

A simple form of multiple choice question with just the two choices: True and False.

orange check mark green check mark

Short Answer

Allows a response of one or a few words that is graded by comparing against various model answers, which may contain wildcards.

orange check mark green check mark

Numerical response

Allows a numerical response, possibly with units, that is graded by comparing against various model answers, possibly with tolerances.

orange check mark green check mark

Matching

Matching questions ask the learner to match multiple question stems to multiple possible answers.

orange check mark green check mark

Essay

An essay question is a free-response text area where learners can enter larger blocks of text in response to your question. These questions are not scored by the system and require manual grading.

orange check mark green check mark

Calculated

Calculated questions are like numerical questions but with the numbers used selected randomly from a set when the quiz is taken.

green check mark

Calculated Simple

A simpler version of calculated questions which are like numerical questions but with the numbers used selected randomly from a set when the quiz is taken.

green check mark

Drag and Drop into Text

Missing words in the question text are filled in using drag and drop.

green check mark

Drag and Drop Markers

Markers are dragged and dropped onto a background image.

green check mark

Drag and Drop onto Image

Images or text labels are dragged and dropped into drop zones on a background image.

green check mark

Embedded Answers (Cloze)

These consist of a passage of text that has various answers embedded within it, including multiple choice, short answers, and numerical answers. 

orange check mark green check mark

Select Missing Words

Missing words in the question text are filled in using dropdown menus.

green check mark

Description

This is not a question and instead allows you to show some text (and possibly graphics) without requiring an answer.

orange check mark green check mark

Back to TOPICS


Multiple Choice

Allows the selection of a single or multiple responses from a pre-defined list. The total grade must add up to 100%. If a single answer is correct, one answer must have the grade set to 100%.

multipleChoice.PNG

MC questions have one <answer> tag for each choice. Each choice can carry feedback and score weighting (by using the fraction attribute). In addition, a MC question has the following tags:

  • single (values: true/false)
  • shuffleanswers (values: 1/0)
  • correctfeedback
  • partiallycorrectfeedback
  • incorrectfeedback
  • answernumbering (allowed values: 'none', 'abc', 'ABCD' or '123')

The <single> tag is used to distinguish single response (radio button) and multiple response (checkbox) variants.

<question type="multichoice">
<answer fraction="100">
<text>The correct answer</text>
<feedback><text>Correct!</text></feedback>
</answer>
<answer fraction="0">
<text>A distractor</text>
<feedback><text>Ooops!</text></feedback>
</answer>
<answer fraction="0">
<text>Another distractor</text>
<feedback><text>Ooops!</text></feedback>
</answer>
<shuffleanswers>1</shuffleanswers>
<single>true</single>
<answernumbering>abc</answernumbering>
</question>

True/False

Two answer tags are given, one which is true, and one which is false. The fraction attribute of the answer tag identifies which option is correct (100) and which is false (0). Feedback is supported. The following example shows the format when true is the correct answer and false is wrong.

<question type="truefalse">
<answer fraction="100">
<text>true</text>
<feedback><text>Correct!</text></feedback>
</answer>
<answer fraction="0">
<text>false</text>
<feedback><text>Ooops!</text></feedback>
</answer>
</question>

Download sample XML for True/False question type

download button

 

Back to TOPICS

Short Answer

The short answer question type supports alternative correct responses, each with its own weighting and feedback. The XML format uses one <answer> tag for each of the alternative correct answers.

The <usecase> tag toggles case-sensitivity with the values 1/0.

<question type="shortanswer">
<answer fraction="100">
<text>The correct answer</text>
<feedback><text>Correct!</text></feedback>
</answer>
 
<question type="shortanswer">
<answer fraction="100">
<text>The correct answer</text>
<feedback><text>Correct!</text></feedback>
</answer>
<answer fraction="100">
<text>An alternative answer</text>
<feedback><text>Correct!</text></feedback>
</answer>
</question>

Download sample XML for Short Answer question type

download button

 

Back to TOPICS

Numerical Response

Allows a numerical response, possibly with units, that is graded by comparing against various model answers, possibly with tolerances.

The following is a simplified version of the XML format for numerical responses.

<question type="numerical">
<name>
<text>14</text>
</name>
<questiontext format="html">
<text>An electric motor drives a stirrer fitted with a horizontal cylinder...."</text>
</questiontext>
<generalfeedback format="html">
<text></text>
</generalfeedback>
<defaultgrade>4.0000000</defaultgrade>
<penalty>0.3333333</penalty>
<hidden>0</hidden>
<answer fraction="100" format="moodle_auto_format">
<text>10.8</text>
<feedback format="html">
<text></text>
</feedback>
<tolerance>0</tolerance>
</answer>
<units>
<unit>
<multiplier>1</multiplier>
<unit_name>kJ</unit_name>
</unit>
</units>
<unitgradingtype>1</unitgradingtype>
<unitpenalty>0.1000000</unitpenalty>
<showunits>0</showunits>
<unitsleft>0</unitsleft>
</question>

Lambda Learn also supports a <tolerance> tag (how accurate must the number be?) and one or more <unit> tags.

Unit tags have names and multipliers. E.g. if the main answer is in kilometres, an additional answer could be the equivalent in metres with a multiplier of 1000.

Download sample XML for Numerical Response  question type

download button

 

Back to TOPICS

Matching

Matching questions ask the learner to match multiple question stems to multiple possible answers.

Pair matching responses use the <shuffleanswers> tag to determine whether the order of the items should be randomized.

Each pair is contained inside a <subquestion> tag. The first item of each pair is contained with a <text> tag, while the second has an <answer> tag around it as well.

<question type="matching">
<subquestion>
<text>This is the 1st item in the 1st pair.</text>
<answer>
<text>This is the 2nd item in the 1st pair.</text>
</answer>
</subquestion>
<subquestion>
<text>This is the 1st item in the 2nd pair.</text>
<answer>
<text>This is the 2nd item in the 2nd pair.</text>
</answer>
</subquestion>
<shuffleanswers>true</shuffleanswers>
</question>

 

Download sample XML for Matching question type

download button

 

 

 

Back to TOPICS

Essay

An essay question is a free-response text area where learners can enter larger blocks of text in response to your question.

These questions are not scored by the system and require manual grading. An example of the essay type question.

<question type="essay">
<answer fraction="0">
<text>Describe the key differences between ice cream and gelato.</text>
</answer>
</question>

There isn't an answer and there isn't a grade in this case.

Download sample XML for Essay question type

download button

 

Back to TOPICS

Calculated Simple

Calculated questions are like numerical questions but with the numbers used selected randomly from a set when the quiz is taken.

<question type="calculatedsimple">
<name>
<text>Calculated simple test</text>
</name>
<questiontext format="html">
<text><![CDATA[If I have {kittens} kittens and pet insurance costs £5 per animal -
how much do I have to spend on pet insurance in total?]]>
</text>
</questiontext>
<generalfeedback format="html">
<text></text>
</generalfeedback>
<defaultgrade>1.0000000</defaultgrade>
<penalty>0.3333333</penalty>
<hidden>0</hidden>
<synchronize>0</synchronize>
<single>0</single>
<answernumbering>abc</answernumbering>
<shuffleanswers>0</shuffleanswers>
<correctfeedback>
<text></text>
</correctfeedback>
<partiallycorrectfeedback>
<text></text>
</partiallycorrectfeedback>
<incorrectfeedback>
<text></text>
</incorrectfeedback>
<answer fraction="100">
<text>{kittens}*5</text>
<tolerance>0.01</tolerance>
<tolerancetype>1</tolerancetype>
<correctanswerformat>1</correctanswerformat>
<correctanswerlength>0</correctanswerlength>
<feedback format="html">
<text></text>
</feedback>
</answer>
<unitgradingtype>0</unitgradingtype>
<unitpenalty>0.1000000</unitpenalty>
<showunits>3</showunits>
<unitsleft>0</unitsleft>
<dataset_definitions>
<dataset_definition>
<status>
<text>private</text>
</status>
<name>
<text>kittens</text>
</name>
<type>calculatedsimple</type>
<distribution><text>uniform</text>
</distribution>
<minimum><text>1.0</text>
</minimum>
<maximum><text>10.0</text>
</maximum>
<decimals><text>1</text>
</decimals>
<itemcount>3</itemcount>
<dataset_items>
<dataset_item>
<number>1</number>
<value>8</value>
</dataset_item>
<dataset_item>
<number>2</number>
<value>3</value>
</dataset_item>
<dataset_item>
<number>3</number>
<value>5</value>
</dataset_item>
</dataset_items>
<number_of_items>3</number_of_items>
</dataset_definition>
</dataset_definitions>
</question>

Download sample XML for Calculated question type

download button

 

Back to TOPICS

Calculated Simple

A simpler version of calculated questions which are like numerical questions but with the numbers used selected randomly from a set when the quiz is taken.

<question type="calculatedsimple">
   <name>
     <text>Calculated simple test</text>
   </name>
   <questiontext format="html">
     <text><![CDATA[<p>If I have {kittens} kittens and pet insurance costs $5 per animal -
How much do I have to spend on pet insurance in total?</p>]]>
</text>
   </questiontext>
   <generalfeedback format="html">
     <text></text>
   </generalfeedback>
   <defaultgrade>1.0000000</defaultgrade>
   <penalty>0.3333333</penalty>
   <hidden>0</hidden>
   <synchronize>0</synchronize>
   <single>0</single>
   <answernumbering>abc</answernumbering>
   <shuffleanswers>0</shuffleanswers>
   <correctfeedback>
     <text></text>
   </correctfeedback>
   <partiallycorrectfeedback>
     <text></text>
   </partiallycorrectfeedback>
   <incorrectfeedback>
     <text></text>
   </incorrectfeedback>
   <answer fraction="100">
     <text>{kittens}*5</text>
     <tolerance>0.01</tolerance>
     <tolerancetype>1</tolerancetype>
      <correctanswerformat>1</correctanswerformat>
     <correctanswerlength>0</correctanswerlength>
     <feedback format="html">
       <text></text>
     </feedback>
   </answer>
 <unitgradingtype>0</unitgradingtype>
   <unitpenalty>0.1000000</unitpenalty>
   <showunits>3</showunits>
   <unitsleft>0</unitsleft>
   <dataset_definitions>
     <dataset_definition>
       <status><text>private</text></status>
       <name><text>kittens</text></name>
       <type>calculatedsimple</type>
    <distribution>
     <text>uniform</text>
  </distribution>
  <minimum><text>1.0</text>
  </minimum>
  <maximum><text>10.0</text>
  </maximum>
  <decimals><text>1</text></decimals>
  <itemcount>2</itemcount>
 <dataset_items>
<dataset_item>
        <number>1</number>
        <value>8</value>
      </dataset_item>
      <dataset_item>
        <number>2</number>
        <value>5</value>
      </dataset_item>
    </dataset_items>
     <number_of_items>2</number_of_items>
     </dataset_definition>
   </dataset_definitions>
</question>

Download sample XML for Calculated Simple question type

download button

Back to TOPICS

Drag and Drop Into Text

Missing words in the question text are filled in using drag and drop.

<question type="ddwtos">
   <name>
      <text>Drag and drop into text test</text>
   </name>
   <questiontext format="html">
      <text><![CDATA[<p>This is an example of a [[1]]. It starts with a [[2]] and end with a [[3]].</text>
   </questiontext>
   <generalfeedback format="html">
      <text></text>
   </generalfeedback>
   <defaultgrade>1.0000000</defaultgrade>
   <penalty>0.3333333</penalty>
   <hidden>0</hidden>
   <shuffleanswers>0</shuffleanswers>
   <correctfeedback format="html">
      <text>Your answer is correct.</text>
   </correctfeedback>
   <partiallycorrectfeedback format="html">
      <text>Your answer is partially correct.</text>
   </partiallycorrectfeedback>
   <incorrectfeedback format="html">
      <text>Your answer is incorrect.</text>
   </incorrectfeedback>
   <shownumcorrect/>
   <dragbox>
      <text>sentence</text>
      <group>1</group>
   </dragbox>
   <dragbox>
      <text>capital letter</text>
      <group>1</group>
   </dragbox>
   <dragbox>
      <text>full stop</text>
      <group>1</group>
   </dragbox>
   <dragbox>
      <text>paragraph</text>
      <group>1</group>
   </dragbox>
   <dragbox>
      <text>word</text>
      <group>1</group>
   </dragbox>
   <dragbox>
      <text>comma</text>
      <group>1</group>
   </dragbox>
</question>

Download sample XML for Drag and Drop into Text question type

download button

 

Drag and Drop Markers

Markers are dragged and dropped onto a background image.

This is a shortened xml version of the Drag and Drop Markers question type.

<question type="ddmarker">
<name>
<text>Drag and drop markers test</text>
</name>
<questiontext format="html">
<text><![CDATA[<p>Label the colours of the rainbow.</p>]]></text>
</questiontext>
<generalfeedback format="html">
<text></text>
</generalfeedback>
<defaultgrade>1.0000000</defaultgrade>
<penalty>0.3333333</penalty>
<hidden>0</hidden>
<shuffleanswers/>
<correctfeedback format="html">
<text>Your answer is correct.</text>
</correctfeedback>
<partiallycorrectfeedback format="html">
<text>Your answer is partially correct.</text>
</partiallycorrectfeedback>
<incorrectfeedback format="html">
<text>Your answer is incorrect.</text>
</incorrectfeedback>
<shownumcorrect/>
<file name="cloud-346706_960_720_600x400.png" encoding="base64"></file>
<drag>
<no>1</no>
<text>Red</text>
<infinite/>
<noofdrags>1</noofdrags>
</drag>
<drag>
<no>2</no>
<text>Orange</text>
<infinite/>
<noofdrags>1</noofdrags>
</drag>
<drop>
<no>1</no>
<shape>circle</shape>
<coords>230,50;30</coords>
<choice>1</choice>
</drop>
<drop>
<no>2</no>
<shape>circle</shape>
<coords>270,70;30</coords>
<choice>2</choice>
</drop>
</question>

Download sample XML for Drag and Drop Markers question type

download button

Drag and Drop Onto Image

Images or text labels are dragged and dropped into drop zones on a background image. 

An example xml of the drag and drop onto image type question.

<question type="ddimageortext">
<name>
<text><![CDATA[Sequencing using drag & drop onto image Q type white]]></text>
</name>
<questiontext format="html">
<text><![CDATA[<p><b>What is important to know on taking a history form the man?
Or the questions from most to least important, starting from the top.</b></p>]]>
</text>
</questiontext>
<generalfeedback format="html">
<text><![CDATA[<p></p> <p> </p>]]></text>
<file></file>
</generalfeedback>
<defaultgrade>1.0000000</defaultgrade>
<penalty>0.3333333</penalty>
<hidden>0</hidden>
<shuffleanswers/>
<correctfeedback format="html">
<text><![CDATA[<p>Your answer is correct.</p>]]></text>
</correctfeedback>
<partiallycorrectfeedback format="html">
<text><![CDATA[<p>Your answer is partially correct.</p>]]></text>
</partiallycorrectfeedback>
<incorrectfeedback format="html">
<text><![CDATA[<p>Your answer is incorrect.</p>]]></text>
</incorrectfeedback>
<shownumcorrect/>
<file></file>
<drag>
<no>1</no>
<text>past medical history, any recent fall, injury</text>
<draggroup>1</draggroup>
</drag>
<drag>
<no>2</no>
<text>how long has the patient had the symptoms?</text>
<draggroup>1</draggroup>
</drag>
<drop>
<text></text>
<no>1</no>
<choice>1</choice>
<xleft>115</xleft>
<ytop>30</ytop>
</drop>
<drop>
<text></text>
<no>2</no>
<choice>2</choice>
<xleft>115</xleft>
<ytop>70</ytop>
</drop>
</question>

Download sample XML for Drag and Drop onto Image question type

download button

 

Back to TOPICS

Embedded Answers (Cloze)

These consist of a passage of text that has various answers embedded within it, including multiple choice, short answers, and numerical answers. The editor has been modified and allows you to test if your syntax is correct. 

<question type="cloze">
<name>
<text>Embedded answers (cloze) test</text>
</name>
<questiontext format="html">
<text><![CDATA[<p>Match the following cities with the correct state:&nbsp;</p>
<p>* Charlotte: {1:MULTICHOICE:=North Carolina#OK~Georgia#Wrong}&nbsp;</p>
<p>* Jacksonville: {1:MULTICHOICE:Arizona#Wrong~%100%Florida#OK}&nbsp;</p>
<p>* Cleveland: {1:MULTICHOICE:=Ohio#OK~Kentucky#Wrong}&nbsp;</p>
<p>* Green Bay: {1:MULTICHOICE:%0%California#Wrong~=Wisconsin#OK}&nbsp;</p>
<p>The capital of Wales is {1:SHORTANSWER:%100%Cardiff#Congratulations!
~%50%Swansea#No, that is the second largest city in Wales (after Cardiff).~*#Wrong answer.
The capital of Wales is Cardiff, of course.}.<br></p>]]>
</text>
</questiontext>
<generalfeedback format="html">
<text></text>
</generalfeedback>
<penalty>0.3333333</penalty>
<hidden>0</hidden>
</question>

Download sample XML for Short Answer question type

download button

Select Missing Words

Missing words in the question text are filled in using dropdown menus.
 
<question type="gapselect">
<name>
<text>Select missing words test</text>
</name>
<questiontext format="html">
<text>
<![CDATA[<p>Roses are [[1]] and violets are [[2]].&nbsp;</p>]]>
</text>
</questiontext>
<generalfeedback format="html">
<text></text>
</generalfeedback>
<defaultgrade>1.0000000</defaultgrade>
<penalty>0.3333333</penalty>
<hidden>0</hidden>
<shuffleanswers>0</shuffleanswers>
<correctfeedback format="html">
<text>Your answer is correct. </text>
</correctfeedback>
<partiallycorrectfeedback format="html">
<text>Your answer is partially correct.</text>
</partiallycorrectfeedback>
<incorrectfeedback format="html">
<text>Your answer is incorrect. </text>
</incorrectfeedback>
<shownumcorrect/>
<selectoption>
<text>red</text>
<group>1</group>
</selectoption>
<selectoption>
<text>blue</text>
<group>2</group>
</selectoption>
<selectoption>
<text>purple</text>
<group>1</group>
</selectoption>
<selectoption>
<text>white</text>
<group>1</group>
</selectoption>
<selectoption>
<text>orange</text>
<group>2</group>
</selectoption>
<selectoption>
<text>green</text>
<group>2</group>
</selectoption>
</question>

Download sample XML for Select Missing Words question type

download button

 

Back to TOPICS

Description  

This is not a question and instead allows you to show some text (and possibly graphics) without requiring an answer. It is more of a label than a question type and may act as an introduction to a new section or may contain a resource (such as a video) that will be the basis for further questions.

This response type has no further tags other than those contained in the question header (such as <questiontext>).

<question type="description">
<name>
<text>Oxidising and Reducing Agents Description</text>
</name>
<questiontext format="html">
<text><![CDATA[<p>Oxidising and Reducing Agents</p>
<p>Determine what the oxidising agent and reducing agents are in each reaction.</p>]]></text>
</questiontext>
</question>
 

Back to TOPICS


Text Formats

XML files should explicitly specify the text format (htmlplain_text and markdown - these correspond to the constants: FORMAT_HTML, FORMAT_MOODLE, etc used in the LMS code) for each piece of content.

By default, the format should be specified on the parent of the <text> element. 

If the format is not specified for the questiontext, then html is the default. If the format is not specified on any other part of the question, then the format of the questiontext is the default.


Back to TOPICS