Import a Moodle Glossary

Moodle glossary imports need a file in XML format. Here is how I did it for Moodle 3.8

First create a glossary with two entries. Export as XML and you have an example of the file you need.

I used a simple text editor to examine the file. Each entry in the table is sandwiched between entry tags

<?xml version="1.0" encoding="UTF-8"?>
<GLOSSARY>
  <INFO>
    <NAME>Chinese</NAME>
    <INTRO></INTRO>
    <INTROFORMAT>1</INTROFORMAT>
    <ALLOWDUPLICATEDENTRIES>0</ALLOWDUPLICATEDENTRIES>
    <DISPLAYFORMAT>dictionary</DISPLAYFORMAT>
    <SHOWSPECIAL>1</SHOWSPECIAL>
    <SHOWALPHABET>1</SHOWALPHABET>
    <SHOWALL>1</SHOWALL>
    <ALLOWCOMMENTS>0</ALLOWCOMMENTS>
    <USEDYNALINK>1</USEDYNALINK>
    <DEFAULTAPPROVAL>1</DEFAULTAPPROVAL>
    <GLOBALGLOSSARY>0</GLOBALGLOSSARY>
    <ENTBYPAGE>10</ENTBYPAGE>
    <ENTRIES>

The XML is nicely formatted to help a human reader but it is not necessary. We can create every entry between entry tags as a single line.

There are two bits of information we must supply for a simple glossary, the word and its definition. There are three bits of XML to add, the section before the definition, the section between the word and definition and the section after the definition. Here is a sample entry we must replicate.

<ENTRY> <CONCEPT>abandon</CONCEPT> <DEFINITION>vt.遗弃 n.放任,狂热</DEFINITION><FORMAT>1</FORMAT><USEDYNALINK>0</USEDYNALINK><CASESENSITIVE>0</CASESENSITIVE><FULLMATCH>0</FULLMATCH><TEACHERENTRY>1</TEACHERENTRY></ENTRY>

And the last section of the XML file is

    </ENTRIES>
  </INFO>
</GLOSSARY>

Create a 5 column spreadsheet. Column 1 is all the XML before the word abandon ie <ENTRY> <CONCEPT>, all on one line. Column 2 is the entry (abandon), column 3 is the XML starting with </CONCEPT> up to <DEFINITION>, column 4 is the definition, then the rest of the XML up to </ENTRY>

Column 6 uses a formula to concatenate columns 1 to 5. Add your words and definitions to columns 2 and 4 and you are good to go.

Now copy all of column 6 to replace the area between the entries tag in your exported file. And you have an XML file ready to import