We're currently working on documenting the new features and improvements in 5.2, ready for its release soon.

Feedback Import

From MoodleDocs

Feedback XML format

The Feedback activity supports importing and exporting questions via an XML file format. This is separate from the Moodle XML format used by the Question bank — the Feedback XML format is specific to the Feedback activity module and has its own structure.

This page documents the complete XML format used by mod/feedback/import.php and the corresponding export function, based on the Moodle source code. It is intended as a reference for developers, integrators, and AI tools that need to programmatically generate Feedback activity surveys.

Overview

The Feedback XML format allows you to:

  • Export all questions from a Feedback activity as a .xml file
  • Import questions into a new or existing Feedback activity
  • Move questions between Moodle instances where the Template tool is not applicable

To import: Go to your Feedback activity → Templates tab → Import questions. You can choose to delete existing items or append to them.

To export: Go to your Feedback activity → Templates tab → Export questions.

File structure

The XML file must be encoded in UTF-8 without BOM (Byte Order Mark). The <?xml> declaration must be the very first line of the file with no blank lines before it.

The overall structure is:

<?xml version="1.0" encoding="UTF-8" ?>
<FEEDBACK VERSION="200701" COMMENT="XML-Importfile for mod/feedback">
     <ITEMS>
          <ITEM TYPE="..." REQUIRED="...">
               ...child elements...
          </ITEM>
          <ITEM TYPE="..." REQUIRED="...">
               ...child elements...
          </ITEM>
     </ITEMS>
</FEEDBACK>

Root element: FEEDBACK

Attribute Required Description
VERSION Yes Must be exactly 200701. The import code checks this value and will reject the file if it does not match.
COMMENT No Optional comment. Moodle's export uses XML-Importfile for mod/feedback.

Container element: ITEMS

The <ITEMS> element is a simple container that wraps all <ITEM> elements. There must be exactly one <ITEMS> element inside <FEEDBACK>.

Item elements: ITEM

Each <ITEM> element represents one question, label, or page break. Items are imported in document order and assigned sequential positions.

ITEM attributes
Attribute Required Description
TYPE Yes The item type. See #Item types below for the complete list.
REQUIRED Yes 1 if the question must be answered, 0 if optional. Set to 0 for labels, page breaks, and info items.
ITEM child elements

Every <ITEM> must contain all of the following child elements, even if their value is empty. All values must be wrapped in <![CDATA[...]]> sections, including empty values (<![CDATA[]]>). This matches the format produced by Moodle's export and is required for reliable import.

Element Description
ITEMID A numeric identifier for the item. Used for dependency mapping between items. On import, Moodle remaps these IDs, so you can use any unique integer (e.g. sequential from 1). Set to 0 if you do not use dependencies.
ITEMTEXT The question text displayed to the user. For label and captcha types, this is ignored on import (set to empty). For all other question types, this is the question/prompt.
ITEMLABEL An optional label identifier used for the dependence feature. This is NOT the display text — it is a short identifier that can be referenced by dependent items. For label and captcha types, this is ignored (set to empty).
PRESENTATION Type-specific presentation data that controls how the item is rendered. The format varies by item type — see #Item types for details.
OPTIONS Additional display options. For multichoice items, this can contain layout flags (e.g. h for horizontal). Usually empty for other types.
DEPENDITEM The ITEMID of another item that this item depends on. Set to 0 for no dependency. When set, this item is only shown if the user selected the value specified in DEPENDVALUE for the referenced item.
DEPENDVALUE The value that the dependent item must have for this item to be shown. Empty if no dependency.
Template for a single item
          <ITEM TYPE="multichoice" REQUIRED="1">
               <ITEMID>
                    <![CDATA[1]]>
               </ITEMID>
               <ITEMTEXT>
                    <![CDATA[Your question text here]]>
               </ITEMTEXT>
               <ITEMLABEL>
                    <![CDATA[]]>
               </ITEMLABEL>
               <PRESENTATION>
                    <![CDATA[r>>>>>Option A
|Option B
|Option C]]>
               </PRESENTATION>
               <OPTIONS>
                    <![CDATA[]]>
               </OPTIONS>
               <DEPENDITEM>
                    <![CDATA[0]]>
               </DEPENDITEM>
               <DEPENDVALUE>
                    <![CDATA[]]>
               </DEPENDVALUE>
          </ITEM>

Item types

The following item types are supported by the Feedback activity. The TYPE attribute value is shown for each.

multichoice

Multiple choice question (unrated). Can be rendered as radio buttons (single answer), checkboxes (multiple answers), or a dropdown list (single answer), depending on the presentation prefix.

PRESENTATION format:

{prefix}>>>>>{option1}
|{option2}
|{option3}

The prefix determines the display style:

Prefix Display style Selection
r Radio buttons Single answer
c Checkboxes Multiple answers
d Dropdown list Single answer

Example — radio buttons (single answer):

<PRESENTATION>
     <![CDATA[r>>>>>Strongly disagree
|Disagree
|Neutral
|Agree
|Strongly agree]]>
</PRESENTATION>

Example — checkboxes (multiple answers):

<PRESENTATION>
     <![CDATA[c>>>>>Email
|Slack
|Phone
|In person]]>
</PRESENTATION>

Example — dropdown list:

<PRESENTATION>
     <![CDATA[d>>>>>Engineering
|Marketing
|Sales
|Support]]>
</PRESENTATION>

OPTIONS field:

The OPTIONS element can control layout for radio buttons and checkboxes:

Value Meaning
(empty) Vertical layout (default)
h Horizontal layout

Notes:

  • Options are separated by a newline followed by a pipe character (\n|). This matches Moodle's export format. Using pipe alone on a single line (without newlines) may also work, but the newline format is recommended for compatibility.
  • The "Not selected" option is automatically added for non-required radio button questions unless hidden via the activity settings.
  • When using the d (dropdown) prefix, a "Not selected" default is shown at the top.

multichoicerated

Multiple choice question with numeric values (rated). Each option has an associated integer value, which allows Moodle to calculate averages in the analysis view. Can be radio buttons, checkboxes, or dropdown — same prefix system as multichoice.

PRESENTATION format:

{prefix}>>>>>{value1}####{label1}
|{value2}####{label2}
|{value3}####{label3}

Each option uses the format {integer_value}####{display_label} where:

  • {integer_value} is the numeric value stored and used for analysis/averages
  • #### is a literal separator (four hash characters)
  • {display_label} is the text shown to the user

Example — rated radio buttons (Likert scale):

<PRESENTATION>
     <![CDATA[r>>>>>1####1 - Strongly disagree
|2####2
|3####3
|4####4
|5####5 - Strongly agree]]>
</PRESENTATION>

Example — rated checkboxes:

<PRESENTATION>
     <![CDATA[c>>>>>1####Writing and editing
|2####Coding and debugging
|3####Data analysis
|4####Brainstorming]]>
</PRESENTATION>

Notes:

  • The integer values do not need to be sequential but typically are (1, 2, 3...).
  • In the Feedback analysis view, Moodle will display the average of the numeric values.
  • Use the r prefix for Likert-style scales, c for "select all that apply" where you still want numeric values.

textarea

A multi-line text input box for longer free-text responses.

PRESENTATION format:

{width}|{height}

Where:

  • {width} is the number of columns (character width of the text area)
  • {height} is the number of rows (visible lines)

Example:

<PRESENTATION>
     <![CDATA[60|5]]>
</PRESENTATION>

This creates a text area 60 characters wide and 5 rows tall.

textfield

A single-line text input for short free-text responses.

PRESENTATION format:

{width}|{maxlength}

Where:

  • {width} is the display width of the input field in characters
  • {maxlength} is the maximum number of characters the user can type

Example:

<PRESENTATION>
     <![CDATA[30|255]]>
</PRESENTATION>

This creates a text field 30 characters wide with a 255-character maximum.

numeric

A numeric input that accepts a number within a specified range.

PRESENTATION format:

{range_from}|{range_to}

Where:

  • {range_from} is the minimum acceptable value
  • {range_to} is the maximum acceptable value

Use empty strings or a dash for unbounded ranges.

Example:

<PRESENTATION>
     <![CDATA[0|10]]>
</PRESENTATION>

This accepts numeric values from 0 to 10.

Example — unbounded:

<PRESENTATION>
     <![CDATA[|]]>
</PRESENTATION>

This accepts any numeric value.

label

A non-interactive text/HTML block used to add section headings, instructions, or explanatory text between questions. Labels are not questions — they have no response.

Special behaviour on import:

  • ITEMTEXT is ignored and set to empty
  • ITEMLABEL is ignored and set to empty
  • The display content goes in PRESENTATION

PRESENTATION format:

The presentation field contains the HTML content to display. You can use standard HTML tags.

Example:

<ITEM TYPE="label" REQUIRED="0">
     <ITEMID>
          <![CDATA[1]]>
     </ITEMID>
     <ITEMTEXT>
          <![CDATA[]]>
     </ITEMTEXT>
     <ITEMLABEL>
          <![CDATA[]]>
     </ITEMLABEL>
     <PRESENTATION>
          <![CDATA[<h3>Section 1: Your Background</h3>
<p>Please tell us about your experience level.</p>]]>
     </PRESENTATION>
     <OPTIONS>
          <![CDATA[]]>
     </OPTIONS>
     <DEPENDITEM>
          <![CDATA[0]]>
     </DEPENDITEM>
     <DEPENDVALUE>
          <![CDATA[]]>
     </DEPENDVALUE>
</ITEM>

pagebreak

Inserts a page break in the feedback form. Questions before the page break appear on one page; questions after appear on the next. Page breaks have no visible content.

Special behaviour:

  • pagebreak is a virtual type — it has no corresponding feedback_item_pagebreak class. The import code handles it as a special case.
  • All child element values should be empty (except ITEMID and DEPENDITEM which should be 0).

Example:

<ITEM TYPE="pagebreak" REQUIRED="0">
     <ITEMID>
          <![CDATA[0]]>
     </ITEMID>
     <ITEMTEXT>
          <![CDATA[]]>
     </ITEMTEXT>
     <ITEMLABEL>
          <![CDATA[]]>
     </ITEMLABEL>
     <PRESENTATION>
          <![CDATA[]]>
     </PRESENTATION>
     <OPTIONS>
          <![CDATA[]]>
     </OPTIONS>
     <DEPENDITEM>
          <![CDATA[0]]>
     </DEPENDITEM>
     <DEPENDVALUE>
          <![CDATA[]]>
     </DEPENDVALUE>
</ITEM>

info

Displays automatically generated information. This is not a question — it shows contextual data based on the presentation value.

PRESENTATION format:

A single integer that selects what information to display:

Value Information displayed
1 The response timestamp (date and time the feedback was completed)
2 The course name (where the feedback is being completed)
3 The course category

Example:

<PRESENTATION>
     <![CDATA[2]]>
</PRESENTATION>

This displays the course name.

captcha

A CAPTCHA verification to prevent automated form submissions. Rarely needed unless the feedback is on the site front page and open to non-logged-in users.

Special behaviour on import:

  • Like label, the ITEMTEXT and ITEMLABEL are ignored and set to empty.
  • PRESENTATION should be empty.

Example:

<ITEM TYPE="captcha" REQUIRED="0">
     <ITEMID>
          <![CDATA[0]]>
     </ITEMID>
     <ITEMTEXT>
          <![CDATA[]]>
     </ITEMTEXT>
     <ITEMLABEL>
          <![CDATA[]]>
     </ITEMLABEL>
     <PRESENTATION>
          <![CDATA[]]>
     </PRESENTATION>
     <OPTIONS>
          <![CDATA[]]>
     </OPTIONS>
     <DEPENDITEM>
          <![CDATA[0]]>
     </DEPENDITEM>
     <DEPENDVALUE>
          <![CDATA[]]>
     </DEPENDVALUE>
</ITEM>

Legacy type names

Older versions of Moodle used different type names. The import code automatically converts these to their modern equivalents. You should use the modern names for new files, but the legacy names are accepted for backwards compatibility:

Legacy TYPE Converted to Presentation prefix added
radio multichoice r>>>>> prepended
dropdown multichoice d>>>>> prepended
check multichoice c>>>>> prepended
radiorated multichoicerated r>>>>> prepended
dropdownrated multichoicerated d>>>>> prepended

When using legacy types, the presentation prefix is added automatically by the import code, so the PRESENTATION value should contain only the options (without the prefix). When using modern types (multichoice / multichoicerated), you must include the prefix yourself.

Dependencies between items

The Feedback activity supports conditional display of items based on the answer to a previous question. This is configured using the DEPENDITEM and DEPENDVALUE fields.

To set up a dependency:

  1. Assign a meaningful ITEMLABEL to the controlling question (this is the short text identifier, not the question text).
  2. Set DEPENDITEM on the dependent item to the ITEMID of the controlling question.
  3. Set DEPENDVALUE to the value that triggers display of this item.

Notes:

  • On import, Moodle remaps ITEMID values to new database IDs. The dependency references are automatically updated.
  • Set DEPENDITEM to 0 and DEPENDVALUE to empty for items with no dependency (the default).

Complete example

The following is a complete, minimal Feedback XML file demonstrating several item types:

<?xml version="1.0" encoding="UTF-8" ?>
<FEEDBACK VERSION="200701" COMMENT="XML-Importfile for mod/feedback">
     <ITEMS>
          <ITEM TYPE="label" REQUIRED="0">
               <ITEMID>
                    <![CDATA[1]]>
               </ITEMID>
               <ITEMTEXT>
                    <![CDATA[]]>
               </ITEMTEXT>
               <ITEMLABEL>
                    <![CDATA[]]>
               </ITEMLABEL>
               <PRESENTATION>
                    <![CDATA[<h3>Employee Satisfaction Survey</h3>
<p>Please answer the following questions honestly.</p>]]>
               </PRESENTATION>
               <OPTIONS>
                    <![CDATA[]]>
               </OPTIONS>
               <DEPENDITEM>
                    <![CDATA[0]]>
               </DEPENDITEM>
               <DEPENDVALUE>
                    <![CDATA[]]>
               </DEPENDVALUE>
          </ITEM>
          <ITEM TYPE="multichoicerated" REQUIRED="1">
               <ITEMID>
                    <![CDATA[2]]>
               </ITEMID>
               <ITEMTEXT>
                    <![CDATA[How satisfied are you with your role? (1 = Very unsatisfied, 5 = Very satisfied)]]>
               </ITEMTEXT>
               <ITEMLABEL>
                    <![CDATA[]]>
               </ITEMLABEL>
               <PRESENTATION>
                    <![CDATA[r>>>>>1####1 - Very unsatisfied
|2####2
|3####3
|4####4
|5####5 - Very satisfied]]>
               </PRESENTATION>
               <OPTIONS>
                    <![CDATA[]]>
               </OPTIONS>
               <DEPENDITEM>
                    <![CDATA[0]]>
               </DEPENDITEM>
               <DEPENDVALUE>
                    <![CDATA[]]>
               </DEPENDVALUE>
          </ITEM>
          <ITEM TYPE="multichoice" REQUIRED="1">
               <ITEMID>
                    <![CDATA[3]]>
               </ITEMID>
               <ITEMTEXT>
                    <![CDATA[Which department are you in?]]>
               </ITEMTEXT>
               <ITEMLABEL>
                    <![CDATA[]]>
               </ITEMLABEL>
               <PRESENTATION>
                    <![CDATA[d>>>>>Engineering
|Marketing
|Sales
|Support
|Other]]>
               </PRESENTATION>
               <OPTIONS>
                    <![CDATA[]]>
               </OPTIONS>
               <DEPENDITEM>
                    <![CDATA[0]]>
               </DEPENDITEM>
               <DEPENDVALUE>
                    <![CDATA[]]>
               </DEPENDVALUE>
          </ITEM>
          <ITEM TYPE="multichoice" REQUIRED="1">
               <ITEMID>
                    <![CDATA[4]]>
               </ITEMID>
               <ITEMTEXT>
                    <![CDATA[What tools do you use daily? (Select all that apply)]]>
               </ITEMTEXT>
               <ITEMLABEL>
                    <![CDATA[]]>
               </ITEMLABEL>
               <PRESENTATION>
                    <![CDATA[c>>>>>Email
|Slack
|Jira
|Confluence
|Google Docs]]>
               </PRESENTATION>
               <OPTIONS>
                    <![CDATA[]]>
               </OPTIONS>
               <DEPENDITEM>
                    <![CDATA[0]]>
               </DEPENDITEM>
               <DEPENDVALUE>
                    <![CDATA[]]>
               </DEPENDVALUE>
          </ITEM>
          <ITEM TYPE="pagebreak" REQUIRED="0">
               <ITEMID>
                    <![CDATA[5]]>
               </ITEMID>
               <ITEMTEXT>
                    <![CDATA[]]>
               </ITEMTEXT>
               <ITEMLABEL>
                    <![CDATA[]]>
               </ITEMLABEL>
               <PRESENTATION>
                    <![CDATA[]]>
               </PRESENTATION>
               <OPTIONS>
                    <![CDATA[]]>
               </OPTIONS>
               <DEPENDITEM>
                    <![CDATA[0]]>
               </DEPENDITEM>
               <DEPENDVALUE>
                    <![CDATA[]]>
               </DEPENDVALUE>
          </ITEM>
          <ITEM TYPE="textarea" REQUIRED="0">
               <ITEMID>
                    <![CDATA[6]]>
               </ITEMID>
               <ITEMTEXT>
                    <![CDATA[Any additional comments or suggestions?]]>
               </ITEMTEXT>
               <ITEMLABEL>
                    <![CDATA[]]>
               </ITEMLABEL>
               <PRESENTATION>
                    <![CDATA[60|5]]>
               </PRESENTATION>
               <OPTIONS>
                    <![CDATA[]]>
               </OPTIONS>
               <DEPENDITEM>
                    <![CDATA[0]]>
               </DEPENDITEM>
               <DEPENDVALUE>
                    <![CDATA[]]>
               </DEPENDVALUE>
          </ITEM>
          <ITEM TYPE="textfield" REQUIRED="0">
               <ITEMID>
                    <![CDATA[7]]>
               </ITEMID>
               <ITEMTEXT>
                    <![CDATA[Your name (optional)]]>
               </ITEMTEXT>
               <ITEMLABEL>
                    <![CDATA[]]>
               </ITEMLABEL>
               <PRESENTATION>
                    <![CDATA[30|255]]>
               </PRESENTATION>
               <OPTIONS>
                    <![CDATA[]]>
               </OPTIONS>
               <DEPENDITEM>
                    <![CDATA[0]]>
               </DEPENDITEM>
               <DEPENDVALUE>
                    <![CDATA[]]>
               </DEPENDVALUE>
          </ITEM>
          <ITEM TYPE="numeric" REQUIRED="0">
               <ITEMID>
                    <![CDATA[8]]>
               </ITEMID>
               <ITEMTEXT>
                    <![CDATA[How many years have you worked here?]]>
               </ITEMTEXT>
               <ITEMLABEL>
                    <![CDATA[]]>
               </ITEMLABEL>
               <PRESENTATION>
                    <![CDATA[0|50]]>
               </PRESENTATION>
               <OPTIONS>
                    <![CDATA[]]>
               </OPTIONS>
               <DEPENDITEM>
                    <![CDATA[0]]>
               </DEPENDITEM>
               <DEPENDVALUE>
                    <![CDATA[]]>
               </DEPENDVALUE>
          </ITEM>
     </ITEMS>
</FEEDBACK>

Item type quick reference

TYPE attribute Description PRESENTATION format Has response
multichoice Multiple choice (unrated) {r|c|d}>>>>>{opt1}\n|{opt2}\n|{opt3} Yes
multichoicerated Multiple choice (rated/numbered) {r|c|d}>>>>>{val}####{label}\n|{val}####{label} Yes
textarea Multi-line text input {width}|{height} Yes
textfield Single-line text input {width}|{maxlength} Yes
numeric Numeric input with range {min}|{max} Yes
label Static HTML text block HTML content No
pagebreak Page separator (empty) No
info Auto-generated information 1, 2, or 3 No
captcha CAPTCHA verification (empty) No

Troubleshooting

"Cannot load XML" error

This is the most common import error. Check the following:

  1. VERSION attribute: Must be exactly 200701 (as an integer, no quotes needed in the attribute value). The import code checks intval($data['FEEDBACK']['@']['VERSION']) != 200701.
  2. UTF-8 encoding: The file must be valid UTF-8. Do not use a BOM (Byte Order Mark). Moodle's feedback_check_xml_utf8() function validates the encoding.
  3. CDATA wrapping: All child element values should be wrapped in <![CDATA[...]]> sections. This is especially important for values containing special characters (&, <, >, ", ').
  4. All child elements present: Every <ITEM> must contain all seven child elements: ITEMID, ITEMTEXT, ITEMLABEL, PRESENTATION, OPTIONS, DEPENDITEM, DEPENDVALUE. Missing elements will cause PHP errors in the xmlize() parser.
  5. Well-formed XML: Validate your file with an XML parser before uploading. Open the file in a web browser (e.g. Firefox) which will report XML syntax errors.
  6. No blank first line: The <?xml declaration must be the very first character of the file.
  7. Special characters in option text: Avoid unescaped ampersands (&) and angle brackets in text outside of CDATA sections. When in doubt, wrap everything in CDATA.

Items import but display incorrectly

  • Multichoice shows no options: Check that the PRESENTATION value includes the correct prefix (r>>>>>, c>>>>>, or d>>>>>>) followed by pipe-separated options.
  • Label shows no content: For label items, the display content must be in PRESENTATION, not ITEMTEXT. The import code sets ITEMTEXT to empty for labels.
  • Rated values not calculating: Ensure you are using multichoicerated (not multichoice) and that each option uses the {value}####{label} format with four hash characters.

Technical notes

How the import code works

The import is handled by mod/feedback/import.php which calls two key functions:

  1. feedback_load_xml_data($xmlcontent) — Validates UTF-8 encoding, parses the XML using Moodle's xmlize() function, checks the VERSION attribute, and returns the array of ITEM data.
  2. feedback_import_loaded_data(&$data, $feedbackid) — Iterates over each item, maps legacy type names, creates feedback_item database records, and remaps dependency references.

The xmlize() function (from lib/xmlize.php) converts XML into a nested PHP array where:

  • Attributes are accessed via ['@']['ATTRIBUTE_NAME']
  • Child element text content is accessed via ['#']['ELEMENT_NAME'][0]['#']

This is why the exact element names and structure matter — the import code uses hardcoded array paths.

Source code references

  • Import/export logic: mod/feedback/import.php
  • Item type classes: mod/feedback/item/{typename}/lib.php (one directory per type)
  • Database schema: mod/feedback/db/install.xml (the feedback_item table)

See also