Here’s the first question in the new Mr. Moodle era:
Dear Mr. Moodle!
I heard that I can write questions for Moodle Quizzes much faster using XML code. Is that true? I have only basic knowledge of XML and HTML, will I be able to use this properly in a way that saves me time?
If you routinely handle lots of quiz questions and are unfamiliar with XML, you’re in for a treat!
XML is a simple way to organize information into hierarchies. Think of an XML file as a tree made of a trunk and branches that can extend indefinitely. A branch can include any number of sub-branches which are embedded inside the scope of the larger branch.
In practice, the content of each branch is defined by tags, special keywords surrounded by less-than (“
<“) and greater-than (“
>“) symbols. If you have a basic knowledge of HTML, these might look familiar. In fact, the HTML code that structures websites is an example of XML, including the same tree-like structure.
When it comes to the Moodle Quiz, every time you create a question using Moodle’s visual interface and click “Save changes,” Moodle automatically turns the question prompts, choices, answers, and hints into an XML file. You can find this file in Moodle’s folder hierarchy.
Creating your own XML file is relatively simple as long as you follow a few simple rules. You can open a text editor to start building your own question bank!
- The first line of the file should always be
<?xml version="1.0" ?>. Anything different will confuse Moodle.
- The second line creates the “trunk” of the Quiz tree which, simply enough, is
- Since everything else in the tree must be inside the trunk, the last line of the file must always be
</quiz>. Notice the slash symbol, it tells the system that the Quiz ends here.
- Within the opening
</quiz>tags you will add every branch and sub-branch for your quiz. Except for a few special cases, every branch must have an opening and a closing tag.
- Every branch has some special attributes, which are included in the opening tag. This allows you to define important things, such as the type of question you are asking.
- Now it’s time to add questions! Every question is a new branch, which naturally is created by the opening and closing tag pair
<question> </question>. Inside the tags, the most basic structure must include the prompt or question itself and the answers with an indication of what the right response is.
Before checking out the example below, it’s important to keep in mind that every piece of text the student will see must be enclosed withing
<text></text> tags. Here is a fully-functioning example:
<question type="The type of question">
<text>The name of the question</text>
<text>The question itself</text>
<text>A possible right answer to the question</text>
Use the structure above for each question you are adding to your quiz. You can add new tags and attributes depending on the type of question you are asking and to expand its possibilities and behavior. (Of course, it’s a good idea to add more than one possible answer.) You can add feedback, multiple choice weightings, randomization, or multimedia resources to the prompts. Think about the kind of questions you want to create, then take a look at the complete documentation here. And when you are done, see how to upload your XML file here.
You might be asking: Is this really a better option than using Moodle’s visual interface? The answer, of course, is up to you. If you know your way around a code editor or development environment, replicating question structures and filling them out can save you time. (In which case, use an XML parsing tool to test for any typing errors before uploading.) Another popular option is using a Moodle XML converter, which saves you time without having to deal with XML code directly.
So next time you are creating lots of questions for your Moodle Quiz, remember that XML could help you save time!
Have more questions? Submit them to the “Ask Mr. Moodle” Google Form. You can also send us your questions on the contact page or in the comments below.
This Moodle Practice related post is made possible by: eThink Education, a Certified Moodle Partner that provides a fully-managed Moodle experience including implementation, integration, cloud-hosting, and management services. To learn more about eThink, click here.