Importing data into Moodle using VB9
We’ve been developing a new Quiz engine on and off over the last few years. The original quiz was written by me in ASP, and does the job, though the interface for authors to enter new questions proved a bit too clunky, and is probably why it was never used very much.
Enter ASP.NET and a chance to start from scratch and have another go. Except that it turns out writing a quiz engine (complete with some kind of question bank) is not that trivial.
It looks like we may never get to finish the ASP.NET version, as we are now starting a trial of the quiz that comes with Moodle. It appears to have pretty much all the features we require, and someone else has done the hard work already!
Last year we were running some trials of the ASP.NET application, and we wanted to migrate the questions that had already been entered over to Moodle so that they could be re-used.
As of version 1.8, Moodle supports the following formats for importing questions:
- Missing Word
- Blackboard <=5
- Blackboard 6+
- Course Test Manager
- Moodle XML
A surprising omission from that list is the IMS QTI format (thought Moodle does support this for exporting). If you’ve ever done quiz development, you should be aware of IMS and their Question and Test Interoperability specifications.
Seeing as the migration tool will only have a limited lifetime I chose Moodle XML. The format is very simple and is mostly documented. The best way to find out the syntax though is to manually enter in some questions into Moodle, then do an Export.
So now to build the tool. I planned to use .NET, and then I realised this was a good opportunity to try out some of the XML support built into VB9.
In the end it I wrote the tool in a day, and the XML support made it very easy.
Dim Doc As XDocument = \_ <?xml version="1.0" encoding="utf-8" standalone="yes"?> <quiz> <question type="category"\> <category><%= t.TEST.TEST\_TITLE %></category> </question> </quiz>
This example shows how you can insert values into the XML really easily. I do like the fact that the XML looks like XML, not wrapped up inside strings.
I did play around with enforcing an XML schema. There isn’t an official one defined by Moodle, so I tried rolling my own. This then lead to problems with the XML getting lots of xmlns attributes which I didn’t want, so in the end I just did without it.