moodle-xml-rs
Moodle has a specific XML format for importing and exporting questions from Quiz Module.
This project provides a Rust library for generating such XML-based Moodle quizzes. The library attempts to ensure that the generated XML is valid and can be imported into Moodle without a hassle.
Usage
Currently, multiple-choice, true-false and short answer questions are mainly supported.
To install, run:
Then, you can use the library as follows:
use *;
// Create a short answer question, with name and description. Use default case sensitivity which is false.
let mut question1 = new;
// Define the fraction value for the answer, correct answer and correct answer feedback.
let answer = new;
question1.add_answers.unwrap;
// Create a multiple-choice question, with name and description. Set that question has a single answer and questions are shuffled.
// Also the "abc" format is used to show the answers.
let mut question2 = new;
let answers = vec!;
question2.add_answers.unwrap;
// Create a quiz with questions
let mut quiz = new;
// Sets a category for the quiz, which will result as "$course$/capitals" in XML, creating a new category "capitals" if it doesn't exist
// when importing the quiz into Moodle.
let categories = vec!;
quiz.set_categories;
// Generate the XML.
// let filename = "quiz.xml";
// Since this runs as part of tests, we use a temporary file.
let tmp_file = new.unwrap;
quiz.to_xml;
The previous will generate a file named quiz.xml
with the following content:
$course$/capitals/
Knowing capitals part 1
Paris
Yes, correct!
0
Name of question
The correct answer
Correct!
A distractor
Ooops!
Another distractor
Ooops!
true
1
Correct!
Partially correct!
Incorrect!
abc
License
MIT