Format XML Moodle

De MoodleDocs
Aller à :navigation, rechercher

Le format XML est un format spécifique à Moodle pour l'importation et l'exportation de questions à utiliser dans le test. Le format a été développé par la communauté Moodle, mais d'autres logiciels peuvent être compatibles avec ce format à un degré plus ou moins important.

À propos de la validité

L'analyseur syntaxique XML se base sur le fait que le fichier XML est bien conçu et ne détecte pas les erreurs. S'il contient effectivement des erreurs, vous aurez sans doute des problèmes. Si vous avez créé le fichier XML à la main, il est fortement recommandé de le faire vérifier par un logiciel vérificateur de XML avant de l'importer dans Moodle. Une façon simple de faire cela est d'ouvrir le fichier XML dans Firefox ou dans Internet Explorer.

Veuillez noter que les fragments de HTML doivent être à l'intérieur de sections CDATA. Exemple de CDATA :

<questiontext format="html">
      <text><![CDATA[
             Maintenant, je peux inclure tout le code HTML que je veux.
Sans CDATA, les HTML balises auraient nui au XML!! ]]> </text> </questiontext>

Structure globale du fichier XML

Le fichier est rédigé à l'intérieur de balises comme suit. Il est important de s'assurer que la ligne xml est la première ligne du fichier. Une première ligne vide peut transformer votre fichier en une source de frustration.

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

.
.
.

</quiz>

À l'intérieur des balises <quiz> se trouvent les balises <question>. L'une de ces balises <question> peut-être une fausse question avec un type de catégorie pour préciser une catégorie pour l'importation/exportation.

<question type="category">

   <category>
       <text>$course$/XXXX</text>
   </category>

</question>

Où XXXX est le nom de la catégorie. Si la catégorie existe, les questions y seront ajoutées; sinon, une nouvelle catégorie sera créée. Cela fonctionne seulement si vous avez coché la case : Obtenir la catégorie à partir du fichier.

De multiples catégories peuvent être précisées à l'intérieur du même fichier. Ajoutez simplement une autre fausse question « catégorie » chaque fois que vous voulez changer de catégorie et toutes les questions suivantes y seront placées.

Le fichier doit être encodé en UTF8.

Afin de mieux comprendre le format, il est recommandé de créer quelques questions et de les exporter pour voir à quoi ressemble le format XML Moodle.

Balises communes à tous les types de questions

Une question est rédigée comme suit :

<question type="multichoice|truefalse|shortanswer|matching|cloze|essay|numerical|description">

    <name>
        <text>Nom de la question</text>
    </name>
    <questiontext format="html">
        <text>Quelle est la réponse à cette question?</text>
    </questiontext>
    .
    .
    .

</question>

L'attribut "Format" définit le formatage texte Formatting options de la question. Les options sont html (défault), moodle_auto_format, plain_text et markdown. Ce choix affecte la façon dont le texte sera pré-traité avant affichage.

Les autres éléments, dont au moins un élément <answer>, suivent (dans la séquence marquée par des points de suite) comme éléments enfants de la balise <question>. Les éléments liés à une réponse sont décrits ci-après. Plusieurs instances optionnelles des éléments qui suivent peuvent apparaître.

  • penalty
  • generalfeedback
  • defaultgrade
  • hidden

L'élément <image> contient l'URL de toute image incluse dans les textes. A l'intérieur de cet élément <image> un élément <image_base64> peut présenter le contenu brut du fichier image encodé en base64 [1].

Dans les exemples de types de 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.'

Choix Multiple

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>

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>

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>

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>

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>

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

  • Online Moodle XML converter Convert from existing text files glossaries and quizzes to Moodle XML format. Also can convert from Moodle XMl to text.
  • Word Template for generating Moodle XML.
  • MoodleXMLBuilder converts commonly-used test generator output into Moodle XML. MoodleXMLBuilder currently supports converting tests and question banks created in Blackboard, ExamView, TestGen, and EZTest. Images are fully supported within all question fields where images are allowed within the Moodle quiz module.