Source: moodle.org
The XML Format is a Moodle-specific format for importing and exporting questions to be used with the Quiz module. The format has been developed within the Moodle Community but other software may support it to a greater or lesser degree.
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 Moodle. 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 any HTML that I wish. Without the CDATA, the HTML tags would break the XML!! ]]> </text> </questiontext>
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 Moodle XML parser.
<?xml version="1.0" ?> <quiz> `
...
</quiz>
Within the tags are any number of <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
Moodle 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.
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 tag and tag for the XML file to import into Moodle properly.
"Format" selects the Formatting options for the question text. The options are html (the default), moodle_auto_format, plain_text and markdown. The choice effects the way in which the text will be displayed.
Further tags, which usually include at least one tag, follow in the space marked with dots as child nodes to the tag. The response-related tags are listed further down on this page. Various (optional?) tags are possible.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>
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.
``` <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>
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>
``` <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>
The following is a simplified version of the Moodle XML format for numerical responses.
``` <question type="numerical"> <answer fraction="100"> <text>23</text> <feedback><text>Feedback</text></feedback> </answer> ```
</question>
``` <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>
An example of the essay type question...
``` <question type="essay"> <answer fraction="0"> <text></text> </answer> </question> ```
There isn't an answer and there isn't a grade in this case.
Note: prior to 1.7.2 the fraction was expressed as a value between 0 and 1 in a element and the answer value was not enclosed in tags. This format of the essay question type is deprecated but will still be correctly imported if found (for now).Moodle has a question type which consists of taking short answer questions in the same quiz and displaying them as a pair matching exercise. However Moodle is neither able to export nor import this question type.
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.
(This default changed around November 2011. Before that, the default was moodle_auto_format whenever the format was not specified.)