Note: You are currently viewing documentation for Moodle 3.1. Up-to-date documentation for the latest stable version of Moodle is probably available here: Moodle XML format.

Moodle XML format: Difference between revisions

From MoodleDocs
No edit summary
 
 
(96 intermediate revisions by 18 users not shown)
Line 1: Line 1:
The '''Moodle XML format''' is not an officially published standard and may be subject to change at Moodle. Moodle XML format is structurally and functionally very similar to Moodle's [[GIFT]] format. The difference is primarily in the form of expression (XML rather than text-only).
{{Export questions}}
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.


Qedoc exports to and imports from this format. This means that an XML file can be easily generated from any Qedoc module for exporting to Moodle, or vice versa, any XML file generated from Moodle (in the quiz export interface) can be imported into Qedoc.
==A word about validity (and CDATA)==


The documentation here describes the format ''as interpreted and supported'' by Qedoc, and is based on an analysis of the published [http://xref.moodle.org/question/format/xml/format.php.source.html Moodle source code]. Features of Moodle XML which Qedoc does not implement are, so far as known, briefly documented here as well. Third parties may wish to build on this format, bearing in mind that Qedoc can export and import files written in this format. You don't necessarily need to be using Moodle as well to use this format - it just happens to be a format created by Moodle programmers.
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 [http://en.wikipedia.org/wiki/CDATA CDATA sections]. CDATA example:
<code xml>
<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>
</code>


==Overall structure of XML file==
==Overall structure of XML file==


The file is enclosed by tags as follows.
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?>
<code xml>
<quiz>
<?xml version="1.0" ?>
<quiz>
  .
  .
  .
  .
  .
  .
</quiz>
</quiz>
</code>
 
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.
 
<code xml>
<question type="category">
    <category>
        <text>$course$/XXXX</text>
    </category>
</question>
</code>
 
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]]


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. The category feature is not yet supported by Qedoc.
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.


==Tags common to all question types==
==Tags common to all question types==
Line 23: Line 54:
A question is written as follows.
A question is written as follows.


<question type="multichoice|truefalse|shortanswer|match|cloze|essay|numerical|description"
<code xml>
<question type="multichoice|truefalse|shortanswer|matching|cloze|essay|numerical|description">
    <name>
        <text>Name of question</text>
    </name>
     <questiontext format="html">
     <questiontext format="html">
         <text>What is the answer to this question?</text>
         <text>What is the answer to this question?</text>
Line 30: Line 65:
     .
     .
     .
     .
</question>
</question>
</code>
 
Each question requires a <name> tag and <question-text> tag for the XML file to import into Moodle properly.


Note that the ''format'' attribute can have other values, but for Qedoc purposes the value "html" is preferred.
"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 <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. These optional tags are not supported by Qedoc (ignored if present).
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
* penalty
* generalfeedback
* generalfeedback
Line 41: Line 80:
* hidden
* hidden


An interesting tag is the <image> tag which allows a base64-encoded image to be included.  
Even though question tags (non-hierarchical keyowords) are not fully supported in the question engine, they can be imported and exported via XML.
 
<code xml>
<question ...>
  ...
  <tags>
    <tag>
      <text>keyword1</text>
    </tag>
    <tag>
      <text>keyword2</text>
    </tag>
    ...
  </tags>
  ...
</question>
</code>
 
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 [http://www.php.net/manual/en/function.base64-encode.php].


Points for clarification:
'''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.'''
# Exactly how does the <image> tag work?
# Is there an <image_base64> tag? How does this relate?


==Multiple choice==
==Multiple choice==


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


* single ''(values: true/false)''
* single ''(values: true/false)''
* shuffleanswers ''(values: 1/0)''
* shuffleanswers ''(values: 1/0)''
* correctfeedback ''(ignored by Qedoc)''
* correctfeedback  
* partiallycorrectfeedback ''(ignored by Qedoc)''
* partiallycorrectfeedback  
* incorrectfeedback ''(ignored by Qedoc)''
* 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.
The <single> tag is used to distinguish single response (radio button) and multiple response (checkbox) variants.


<question type=multichoice>
<code xml>
  <answer fraction=100>
<question type="multichoice">
  <answer fraction="100">
     <text>The correct answer</text>
     <text>The correct answer</text>
     <feedback><text>Correct!</text></feedback>
     <feedback><text>Correct!</text></feedback>
  </answer>
  </answer>
  <answer fraction=0>
  <answer fraction="0">
     <text>A distractor</text>
     <text>A distractor</text>
     <feedback><text>Ooops!</text></feedback>
     <feedback><text>Ooops!</text></feedback>
  </answer>
  </answer>
  <answer fraction=0>
  <answer fraction="0">
     <text>Another distractor</text>
     <text>Another distractor</text>
     <feedback><text>Ooops!</text></feedback>
     <feedback><text>Ooops!</text></feedback>
Line 74: Line 131:
  <shuffleanswers>1</shuffleanswers>
  <shuffleanswers>1</shuffleanswers>
  <single>true</single>
  <single>true</single>
 
<answernumbering>abc</answernumbering>
Points needing clarification:
</question>
# If the tags ignored by Qedoc are not present in a file exported to Moodle, will the Moodle import fail? Are dummy values required for these tags?
</code>
# Item-specific feedback makes sense for single-response MC responses; while global feedback (''correctfeedback'',''partiallycorrectfeedback'',''incorrectfeedback'') makes sense for multi-response MC responses.
 
See also: [[GIFT Multiple Choice Format]]


== True/false ==
== True/false ==


Two answer tags are given, one which is true, and one which is false. The fraction attribute of the answer tag presumably 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.
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>
<code xml>
  <answer fraction=100>
  <question type="truefalse">
  <answer fraction="100">
     <text>true</text>
     <text>true</text>
     <feedback><text>Correct!</text></feedback>
     <feedback><text>Correct!</text></feedback>
  </answer>
  </answer>
  <answer fraction=0>
  <answer fraction="0">
     <text>false</text>
     <text>false</text>
     <feedback><text>Ooops!</text></feedback>
     <feedback><text>Ooops!</text></feedback>
  </answer>
  </answer>
</question>
</code>


See also: [[GIFT True/False Format]]
== Short answer  ==


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


The short answer question type supports alternative correct responses, each with its own weighting and feedback. Weighting and feedback will be ignored when imported into Qedoc, but alternative responses are understood. The Moodle XML format uses one <answer> tag for each of the alternative correct answers.
The <usecase> tag toggles case-sensitivity with the values 1/0.  


The <usecase> tag toggles case-sensitivity with the values 1/0. It is not supported by Qedoc because in Qedoc case-sensitivity is a quiz property, not a question property.
<code xml>
 
  <question type="shortanswer">
  <question type=shortanswer>
  <answer fraction="100">
  <answer fraction=100>
     <text>The correct answer</text>
     <text>The correct answer</text>
     <feedback><text>Correct!</text></feedback>
     <feedback><text>Correct!</text></feedback>
  </answer>
  </answer>


  <question type=shortanswer>
  <question type="shortanswer">
  <answer fraction=100>
  <answer fraction="100">
     <text>The correct answer</text>
     <text>The correct answer</text>
     <feedback><text>Correct!</text></feedback>
     <feedback><text>Correct!</text></feedback>
  </answer>
  </answer>
  <answer fraction=100>
  <answer fraction="100">
     <text>An alternative answer</text>
     <text>An alternative answer</text>
     <feedback><text>Correct!</text></feedback>
     <feedback><text>Correct!</text></feedback>
  </answer>
  </answer>
 
</question>
See also: [[GIFT Typed Response Format]]
</code>


== Numerical response ==
== Numerical response ==
Line 125: Line 181:
The following is a simplified version of the Moodle XML format for numerical responses.
The following is a simplified version of the Moodle XML format for numerical responses.


  <question type=numerical>
<code xml>
  <answer>
  <question type="numerical">
    ''A number''
  <answer fraction="100">
     <fraction>100</fraction>
     <text>23</text>
     <feedback><text>Feedback</text></feedback>
     <feedback><text>Feedback</text></feedback>
  </answer>
  </answer>
</question>
</code>


Moodle 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. These features are not yet supported by Qedoc.
Moodle 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.


Currently this response is imported into Qedoc as a short answer / typed response.  
'''Note:''' prior to 1.7.2 the fraction was expressed as a value between 0 and 1 in a <fraction> element and the answer value was '''not''' enclosed in <text> tags. This format of the numerical question type is deprecated but will still be correctly imported if found (for now).


See also: [[GIFT Numerical Response Format]]
== Matching ==
 
== Pair matching ==


Pair matching responses use the <shuffleanswers> tag to determine whether the order of the items should be randomized.
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. Feedback and score weighting is not supported by Moodle for this response type.
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. Feedback and score weighting is not supported by Moodle for this response type.


  <question type=match>
<code xml>
  <question type="matching">
  <subquestion>
  <subquestion>
     <text>This is the 1st item in the 1st pair.</text>
     <text>This is the 1st item in the 1st pair.</text>
Line 149: Line 206:
         <text>This is the 2nd item in the 1st pair.</text>
         <text>This is the 2nd item in the 1st pair.</text>
     </answer>
     </answer>
  <subquestion>
  </subquestion>
  <subquestion>
  <subquestion>
     <text>This is the 1st item in the 2nd pair.</text>
     <text>This is the 1st item in the 2nd pair.</text>
Line 155: Line 212:
         <text>This is the 2nd item in the 2nd pair.</text>
         <text>This is the 2nd item in the 2nd pair.</text>
     </answer>
     </answer>
  <subquestion>
  </subquestion>
  <shuffleanswers>true</shuffleanswers>
  <shuffleanswers>true</shuffleanswers>
</question>
</code>


See also: [[GIFT Pair Matching Format]]
== Essay ==


== Other question types ==
An example of the essay type question...


=== Cloze/Gapfill ===
<code xml>
  <question type="essay">
    <answer fraction="0">
        <text></text>
    </answer>
  </question>
</code>


It is not yet known how Moodle deals with this response type. It appears to be supported, but depends on a special format for the <questiontext> tag. It may be like the essay type, in that the user simply types into an incomplete text without the programme actually marking anything or offering any options - the course instructor has to mark it manually.
There isn't an answer and there isn't a grade in this case.  


=== Essay response type ===
'''Note:''' prior to 1.7.2 the fraction was expressed as a value between 0 and 1 in a <fraction> element and the answer value was '''not''' enclosed in <text> tags. This format of the essay question type is deprecated but will still be correctly imported if found (for now).


Not currently supported by Qedoc.
== Other question types ==


=== Regular expression response type ===
=== Cloze ===


The format appears to be identical to short answers / typed responses. Clarification about the differences is needed.
It is supported, and depends on a special format for the <questiontext> tag.
Not currently supported by Qedoc.


=== Description response type===
=== Description response type===


This response type appears to have no further tags other than those contained in the question header (such as <questiontext>).
This response type has no further tags other than those contained in the question header (such as <questiontext>).
Not currently supported by Qedoc.


=== Random matching ===
=== Random matching ===
Line 184: Line 247:
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.
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.


== Unresolved issues ==
==Text formats==
 
Moodle XML files should explicity specify the text format ('''html''', '''moodle_auto_format''', '''plain_text''' and '''markdown''' - these correspond to the constants , FORMAT_HTML, FORMAT_MOODLE, etc used in the Moodle code) for each piece of content. Note that, by default, the format should be specified on the parent of the <text> element. This is slightly odd, but a remnant of history.
 
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.)
 
==Useful utilities==
*[http://vletools.com Online Moodle XML converter] Convert from existing text files glossaries and quizzes to Moodle XML format. Also can convert from Moodle XMl to text.
*[http://finemetronome.com/moodle/ Word Template for generating Moodle XML].
*[http://www.learningseekers.com/products MoXMLE - A Java based application] MoXMLE is a Java based application that converts a Simple TXT file into a Moodle XML format.
 
== See also ==
* [http://www.qedoc.org/index.php?title=Moodle_XML_format Quedoc's Moodle XML documentation]
* [[User:Frank Ralf/Moodle XML1]] (work in progress)
*[[Aiken format]]
*[[XML FAQ]]
*[[Import and export FAQ]]


Moodle XML format does not use CDATA-sections. HTML characters are dealt with by invoking the PHP ''htmlspecialchars'' method, which would need to be reversed by software using any other language. It is not clear how Moodle XML deals with internationalisation.
[[ja:Moodle XMLフォーマット]]
[[de: Moodle XML-Format]]
[[fr:Format XML Moodle]]
[[es:Formato Moodle XML]]

Latest revision as of 11:18, 11 October 2016

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.

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 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>

Overall structure of XML file

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 <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

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.

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 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 <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 keyowords) 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].

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.

Multiple choice

MC questions have one <answer> tag for each choice. Each choice can carry feedback and score weighting (by using the fraction attribute). In addition, an 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>

Short answer

The short answer question type supports alternative correct responses, each with its own weighting and feedback. The Moodle 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>

Numerical response

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>

Moodle 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.

Note: prior to 1.7.2 the fraction was expressed as a value between 0 and 1 in a <fraction> element and the answer value was not enclosed in <text> tags. This format of the numerical question type is deprecated but will still be correctly imported if found (for now).

Matching

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. Feedback and score weighting is not supported by Moodle for this response type.

<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>

Essay

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 <fraction> element and the answer value was not enclosed in <text> tags. This format of the essay question type is deprecated but will still be correctly imported if found (for now).

Other question types

Cloze

It is supported, and depends on a special format for the <questiontext> tag.

Description response type

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

Random matching

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.

Text formats

Moodle XML files should explicity specify the text format (html, moodle_auto_format, plain_text and markdown - these correspond to the constants , FORMAT_HTML, FORMAT_MOODLE, etc used in the Moodle code) for each piece of content. Note that, by default, the format should be specified on the parent of the <text> element. This is slightly odd, but a remnant of history.

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.)

Useful utilities

See also