---
title: "Moodle XML Format: Structure, Example and Import Steps | Formswrite Blog"
description: "See how a Moodle XML quiz file is built, with a full multiple choice example, true/false, short answer, embedded images and the steps to import it."
canonical: https://formswrite.com/blog/moodle-xml-format-example
last-updated: 2026-10-08
---

# Moodle XML Format: Structure, Example and Import Steps

In short

Moodle XML is the most complete way to move questions into Moodle. A file has one root element called quiz, and inside it one question element per question, each with a type attribute such as multichoice, truefalse or shortanswer. Each question carries its text, its answers with a fraction of the grade, optional feedback and, if needed, embedded images.

Below is a complete working file, then the parts you will edit most often.

## A complete multiple choice example

xml`<?xml version="1.0" encoding="UTF-8"?> <quiz>   <question type="category">     <category><text>$course$/top/Unit 1 Geography</text></category>   </question>    <question type="multichoice">     <name><text>Capital of France</text></name>     <questiontext format="html">       <text><![CDATA[<p>What is the capital of France?</p>]]></text>     </questiontext>     <generalfeedback format="html"><text>Paris is the capital and largest city.</text></generalfeedback>     <defaultgrade>1.0000000</defaultgrade>     <penalty>0.3333333</penalty>     <hidden>0</hidden>     <single>true</single>     <shuffleanswers>true</shuffleanswers>     <answernumbering>abc</answernumbering>     <answer fraction="0" format="html"><text>Madrid</text><feedback format="html"><text>Madrid is in Spain.</text></feedback></answer>     <answer fraction="100" format="html"><text>Paris</text><feedback format="html"><text>Correct.</text></feedback></answer>     <answer fraction="0" format="html"><text>Rome</text><feedback format="html"><text>Rome is in Italy.</text></feedback></answer>     <answer fraction="0" format="html"><text>Berlin</text><feedback format="html"><text>Berlin is in Germany.</text></feedback></answer>   </question> </quiz>`

## What the elements do

| Element | Purpose |
| --- | --- |
| quiz | Root of the file, holds all questions |
| question type="category" | Sets the category that the following questions are imported into |
| question type | The question type: multichoice, truefalse, shortanswer, numerical, matching, essay or cloze |
| name | Title shown in the question bank |
| questiontext | The question itself, usually HTML wrapped in CDATA |
| generalfeedback | Feedback shown after the attempt, whichever answer was chosen |
| defaultgrade and penalty | Marks for the question and the penalty for each wrong try in adaptive mode |
| single | true for one correct answer, false for several |
| answer fraction | Percentage of the grade for that answer, from 100 down to negative values |
| feedback inside an answer | Feedback for that specific choice |

## Other question types

True/false uses two answers, one with fraction 100 and one with 0:

xml`<question type="truefalse">   <name><text>Earth orbits the Sun</text></name>   <questiontext format="html"><text><![CDATA[<p>The Earth orbits the Sun.</p>]]></text></questiontext>   <answer fraction="100"><text>true</text></answer>   <answer fraction="0"><text>false</text></answer> </question>`

Short answer lists each accepted response as its own answer, and the usecase element decides whether capitalization matters:

xml`<question type="shortanswer">   <name><text>Capital of Italy</text></name>   <questiontext format="html"><text><![CDATA[<p>What is the capital of Italy?</p>]]></text></questiontext>   <usecase>0</usecase>   <answer fraction="100"><text>Rome</text></answer> </question>`

For several correct answers in a multichoice question, set single to false and give each right answer a positive fraction (for example 50 and 50) and each wrong answer a negative one.

## Adding an image

Images are embedded as base64 inside a file element, and the question text refers to it with the PLUGINFILE placeholder:

xml`<questiontext format="html">   <text><![CDATA[<p>Name this shape.</p><p><img src="@@PLUGINFILE@@/shape.png" alt="A hexagon"/></p>]]></text>   <file name="shape.png" path="/" encoding="base64">iVBORw0KGgo...</file> </questiontext>`

This is why Moodle XML is the format to choose when a question needs a diagram. Aiken cannot do it, and GIFT can only link to an image by URL. The [Aiken vs GIFT vs Moodle XML comparison](/blog/moodle-aiken-vs-gift-vs-xml) shows the full feature table.

## Common reasons an import fails

-   Unescaped characters. Ampersands and angle brackets in plain text must be written as entities, or the HTML wrapped in CDATA.
-   Missing closing tags. One unclosed element invalidates the whole file, so open it in a browser or an XML validator before importing.
-   Wrong encoding. Save as UTF-8 and keep the encoding in the XML declaration.
-   Fractions that do not add up. A single-answer question needs exactly one answer at 100.

## Import steps in Moodle

1.  Open your course and go to the Question bank.
2.  Choose Import.
3.  Select the XML format.
4.  Upload the file and pick the category, or leave the category element in the file to create one.
5.  Click Import and review the list of created questions.

## Generate the file from a document

Writing the tags by hand does not scale past a few questions. Formswrite reads questions from a Word file, PDF, Google Doc or spreadsheet, detects each option and correct answer, and exports Moodle-ready XML. Aiken and GIFT exports are also available for simpler banks. On the free plan the only export is Formswrite Forms, so the Moodle formats are paid. An account is free.

[Convert a document to Moodle XML](/product/documents-to-moodle)

The [Moodle XML generator guide](/blog/moodle-xml-file-generator-simplify-your-quiz-creation) walks through the conversion, and the [Moodle question bank import guide](/blog/moodle-question-bank-import-simplify-your-quiz-management) covers organising categories afterwards.

## FAQ

What is Moodle XML format?

It is Moodle's native XML file format for questions. One file can hold many questions of different types, with their answers, feedback, grades and embedded images. It is also what Moodle produces when you export a question category.

Can I convert Word to Moodle XML?

Yes. You can retype the questions as XML, use a Word template that outputs XML, or use a converter that reads the document and writes the file for you. Formswrite does the last of these and also offers GIFT and Aiken as simpler outputs.

How do I export questions from Moodle as XML?

Go to the Question bank, choose Export, select Moodle XML format, pick the category and download the file. You can import that file into another Moodle site later.

Is Moodle XML better than GIFT?

It is more complete because it supports embedded images, rich formatting and every setting, but it is much harder to write by hand. GIFT is better for quick hand-typed banks, and XML is better for generated files and anything with images.
