Anyone have a script for converting to xml?

Anyone have a script for converting to xml?

by Zane Edwards -
Number of replies: 40
The glossary import is the most tedious aspect of moodle, for something that gets probably the least amount of use! I have hundreds of terms I would like to import into the glossary and I am do not want to spend days doing this. Any alternatives or script magic for this one? I have a word doc and an excel worksheet.

Thanks in advanced!
Average of ratings: -
In reply to Zane Edwards

Re: Anyone have a script for converting to xml?

by Gary Busch -
I am not sure it helps. I have converted Excel spreadsheets, csv files, etc. to XML but it requires an XML Schema as well. I have used Stylus Studio to create every possible form of schema but nothing seems to work. I used to have the glossary working, but now it doesn't want to upload. So if you find a solution, please let me know.
In reply to Zane Edwards

Re: Anyone have a script for converting to xml?

by Just H -
Hi all

Tips as to reliable software for producing an xml file that the glossary will accept would be much appreciated. Similar to Zane, I too have a few hundred terms/acronyms I need to take from printed learning manuals and input to a glossary.

It's going to be a lot of cutting and pasting and doing it online with all the screen refreshes is going to be a major pain in the proverbial. Tried doing a "mail merge" that will get the data into the xml structure but does not get recognised as such even after then cutting and pasting it into html kit and saving as xml angry

There must be an easy way of doing this . . . isn't there! thoughtful
In reply to Just H

Re: Anyone have a script for converting to xml?

by Chris Collman -
Non Xml idea.   I had the same screen refresh problem building a lesson.  Which was before ImportPPT worked well, so I was inserting one image from an OOI webfolder at a time.   Took me 20 minutes per 10 pages, including a 5 minute break after the first 30 pages because of burnout.

I put Moodle on my desktop (about zero refresh as a localhost).  Build my lessons on it and upload them to the production moodle site.  I immediately  knocked off 80 pages in less than 40 minutes  with almost zero error rate.   Just a trick to use incase the easy way can not be found.

Best wishes with XML. Chris
In reply to Chris Collman

Re: Anyone have a script for converting to xml?

by Just H -
Thanks Chris

Not a solution as such to the underlying problem but will help a lot smile

H
In reply to Zane Edwards

Re: Anyone have a script for converting to xml?

by Colin McQueen -
This is a real issue for us. I need to be able to share glossaries for import and I get a file size limit problem.

Sorry, but that file is too big (limit is 10240 bytes)

Is there somewhere I can alter this limit? Surely there must be a csv style import routine we could use?
In reply to Colin McQueen

Re: Anyone have a script for converting to xml?

by Gary Busch -

I've now tried XML Fox, XML Converter,Cookbook and two others to try to restore my glossary. It worked for a long time but I cannot get it restored when I changed my website address. This is an extraordinary waste of my time and the documentation in Moodle is either primitive or misleading.

Average of ratings: Useful (1)
In reply to Gary Busch

Re: Anyone have a script for converting to xml?

by Matt Campbell -
Well, this is going to drive me crazy trying to figure this out, so let me share what I've done and you can let me know if it works for you. 

In Excel 2003, I use an excel spreadsheet with seperated concepts and definitions, then go to Data - XML - XML Source - XML Maps - Add.

I'll then browse to an exported Moodle glossary and click okay.  This opens up a window that gives me the schema.  I drag the concept tag to the top of the terms column, and the definition tag to the top of the definititions column.  I then save this as XML Data.

I then import this into my glossary.

This works fine on both of my 1.6 production sites.  It gives me an error on my 1.6 test site, saying "Can't insert record" for every one of the concepts.

All sites are on the same server.  The Moodle and glossary versions are exactly the same.  Ownerships and permissions to the folders and databases are exactly the same.

So why does this work on my production site and not my test site?


In reply to Matt Campbell

Re: Anyone have a script for converting to xml?

by Matt Campbell -
Okay, I figured it out.  In the XML schema map, pull 'USEDYNALINK', "CASESENSITIVE' and 'FULLMATCH' over to empty columns.  Seems to work now.
In reply to Matt Campbell

Re: Anyone have a script for converting to xml?

by a. z. -

i have done all this, but still "Can't insert record"....

any ideas?

thanx...
In reply to a. z.

Re: Anyone have a script for converting to xml?

by Gary Busch -
I have tried 30 different permutations of XML and Schema; all of which are validated and well-formed. They still will not import into the Glossary. Is this an Open Source feature added to torment us? Please, what is the form in which an XML should be arranged and what is the Schema. This is becoming absurd.
In reply to Gary Busch

Re: Anyone have a script for converting to xml?

by Kristi Dugan -
Here is a way I have found to create the proper XML file for uploading multiple entries to your Moodle Glossary. There is probably a better way, but this worked for me.

Put your terms and definitions in a spreadsheet. Your first column should contain all the terms, the second all the definitions. The headers should be named “term” and “definition”.

Make a dummy glossary entry in Moodle and export the glossary to your desktop. You will use this as your master XML Glossary file template. Open up the XML file in an HTML editor such as Frontpage or Dreamweaver (I used Frontpage at work – I’m sure Dreamweaver would work as well, I'll try when I get home). Minimize this; we’ll come back to it later.

Open a new Word document, save as .txt file. (Important)

Start a mail merge: Tools > Letters and Mailings > Mail Merge

Choose the Directory option in Select document type (Step 1 of 6 in the merge wizard)
Use the ENTRY item template below to set up your merge. We are interested in getting the items into the proper format for the XML file. This is NOT the complete file, just the inner ENTRY items.
<ENTRY>
    <CONCEPT>«term»</CONCEPT>
    <DEFINITION>«definition»</DEFINITION>
    <FORMAT>1</FORMAT>
    <USEDYNALINK>0</USEDYNALINK>
    <CASESENSITIVE>0</CASESENSITIVE>
    <FULLMATCH>0</FULLMATCH>
    <TEACHERENTRY>1</TEACHERENTRY>
</ENTRY>

Use the current document as the starting document (Step 2 of 6)

Use and existing list (Step 3 of 6) Select your spreadsheet with your terms and definitions

Arrange your directory (Step 4 of 6)
Insert the term and definition merge fields by selecting “More items…”

Preview your directory (Step 5 of 6) You only see the first record. Don’t worry.
Complete the merge (Step 6 of 6) All your entries are now nicely XML formatted.

Select all of the resultant “directory” and paste it into the full Glossary XML file that you opened in Dreamweaver or Frontpage, making sure you paste it between the <ENTRIES> and </ENTRIES> tags. You may have the option in your editor to “cleanup the XML formatting” – go ahead and use it.

Save your work and Import it to your Moodle Glossary. Moodle will automatically skip any duplicates.
In reply to Kristi Dugan

Re: Anyone have a script for converting to xml?

by Matt Fedorko -

Kristi,

I made it through a few pages on these forums, with lots of people talking about solutions to this problem, and yours was the first one that looked like I could do it. I was very surprised no one had replied to your suggestion. But here I am, 7 years later, trying this method in Moodle 2.4 and finding that it works very nicely, even for someone who was not even aware of Mail Merge inside Word.

To clarify her directions, for anyone who might like to try this in the future, during the Mail Merge process, you copy and paste the XML code that she has into your document. If you have named the column titles in your spreadsheet "term" and "definition" as she suggests, you do not need to do step 4 of 6 because the "merge fields" she speaks of are the items "<<term>>" and "<<definition>>" that are included in the XML you copied in. Step 4 is just necessary to create those two text strings, so that Word knows to insert one item from the "term" column where <<term>> is in the Word file, and same with definition. If you've titled your columns in your spreadsheet something else, you need to replace <<term>> with <<whatever your title is>> and same with <<definition>>.

Thanks again, Kristi!

In reply to Matt Fedorko

Re: Anyone have a script for converting to xml?

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

Hi Matt,

Seven years is a long time in our "computer age". I'm glad you found Kristi's directions useful. Sadly she will probably never read your thanks, since she is no longer enrolled in this "course" (as you would have found out if you had clicked on the link to her profile).

Again I'm glad her solution worked for you. However I must say I am not a great fan of solutions which involve the use of proprietary software such as MS Word.

ATB

Joseph

In reply to Joseph Rézeau

Re: Anyone have a script for converting to xml?

by Matt Fedorko -

I may not have clicked her name (and I'm not sure why I would have, as I was posting to a public forum, with the hope that all who read would benefit from my experience, despite the salutation at the front of the message which is, I would think, common courtesy), but I do know how to Google "open office" and "mail merge":

http://www.openoffice.org/documentation/HOW_TO/word_processing/writer2_EN.html

 

In reply to Matt Fedorko

Re: Anyone have a script for converting to xml?

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

"Open office", that sounds better. Does this mean that you managed to adapt Kristi's instructions to Open office (rather than to the original MS Word)? If so, that's great.

Joseph

PS.- Sorry if my remark about not clicking Kristi's name sounded flippant. I just wanted to bring to your attention the fact that that user was no longer registered on this moodle.org course and therefore would probably never read your message thanking her, which is a pity.wink Better to "thank in vain" than to forget to thank, of course.approve

In reply to Zane Edwards

Re: Anyone have a script for converting to xml?

by David Fountain -

I have made an Excel spreadsheet that takes two columns, Concept and Definition, and creates a xml file that can be imported into an existing glossary. (Setting up a new glossary to accept the input is not too onerous)

Enter your concepts/definitions in columns A and B and run the macro "PrepareSheetForMoodle".

Not perfect, it will not accept HTML code in the definition and some of the defaults are hard-coded to those we use, but should be easy to change in the macro code if you desire.

Hope this helps.
Dave

 

In reply to David Fountain

Re: Anyone have a script for converting to xml?

by kathryn cruickshanks -
Your prep sheet saved me so much time, I just wanted to say thanks!
In reply to kathryn cruickshanks

Re: Anyone have a script for converting to xml?

by Evan Perry -
Kathryn,

Did you have to do anyhting special to the .xml file prior to importing it into moodle? I've created what I thought was the correct format file to import, but I guess I'm just out of energy. Any insight would be delightful!

I've attached the xml file.
Evan
In reply to Evan Perry

Re: Anyone have a script for converting to xml?

by ian lake -
i ran this file using the macro and could find no errors, it imported perfectly into a test glossary - i am using moodle 1.6.4. later or earlier version may differ

ian
In reply to Evan Perry

Re: Anyone have a script for converting to xml?

by Andy Striemer -
Awesome spreadsheet. Thanks! Worked fine for me with 1.8
In reply to kathryn cruickshanks

Re: Anyone have a script for converting to xml?

by David Fountain -
A kind word goes a long way when you work for free, thank you.
In reply to David Fountain

Re: Anyone have a script for converting to xml?

by Simon Byrnand -

Hi Dave,

I'm trying to use this spreadsheet to import a glossary and I'm having problems with it - it seems that it doesn't encode some punctuation properly - some of the descriptions I'm trying to import have quotation marks - which result in "can't insert record" in moodle.

So I manually edited the quotation marks and changed them to single ticks and the import then gets further, but now its getting stuck on another character. The only non alphabetic characters in the field are commas and hyphens. sad

Any suggestions ?

Regards,
Simon

In reply to Simon Byrnand

Re: Anyone have a script for converting to xml?

by ian lake -
I tried this spreadsheet with a glossary i created for NLN material and eventually succeeded, the problems are what can be considered 'stop' characters and some other oddities I found, i spent hours sorting through the list, i converted it to text, i did search and replace in word and reimported you need to look for

[ ] { } ` ¦ ¬ ^ & / \ | " - (hyphens need to be replaced with minus signs)

and those were just a few of them, how they arrived in the document i was processing i have no idea, but they were there never-the-less. I was eventually forced to process the file, open the xml file scroll down 'til i found an error, open the excel file trace the text correct it rerun the macro and start all over again.

There now some 1700 entries in the glossary. I am looking for a way to add categories using this macro - any ideas? what i know about vb, c, c++, php etc etc would fit on the head of a pin.

if you would like you could send me the offending file and i'll see what i can find.

ian
In reply to ian lake

Re: Anyone have a script for converting to xml?

by David Fountain -
This new prep sheet has a column for you to put in categories. When you import there is a check box to mark that you want to import the categories too, it will create new categories as it imports or use ones you already have in the glossary if they match.

I'm using moodle 1.5.4 but have also tested it with moodle 1.7.2 so hopefully it will work on most versions.
In reply to David Fountain

Re: Anyone have a script for converting to xml?

by ian lake -

Many thanks for this David, it is a fine piece of work

ian

In reply to Simon Byrnand

Re: Anyone have a script for converting to xml?

by David Fountain -
Sorry Simon for not replying I seem to have lost the thread in my email account, I only came back to check when I got a message from someone about the spreadsheet.

I see Ian has had some suggestions for you, I don't think I can add anything to his comments, but if you are still having trouble please let me know and I will look again.
In reply to Simon Byrnand

Re: Anyone have a script for converting to xml?

by David Fountain -
Simon,

Once you have the columns A and B (Concept and definition) as you want them do a replace search that swaps " for &quot; and another that replaces & with &amp; (not forgetting the ; as I do sometimes). I have found that the various brackets and braces are accepted by the import but ¬ does give me problems and I am not sure what 'code' replaces it.

Where I have found something that stops the import, I type it into an empty glossary and then hit the export button to see what it wants in its place.

Dave
In reply to David Fountain

Re: Anyone have a script for converting to xml?

by Simon Byrnand -

Hi Dave,

Thanks for replying. I've been busy on other things recently but I'm back looking at this again - I have a Glossary which has 189 entires in a table in a word document, I'm doing a search and replace to deal with & " < and >. The only one which is actually in the document is ". I'm then pasting that into the spreadsheet and exporting it.

The result I get is:

Total entries: 26
Imported entries: 23 (Rejected entries: 3)

Rejection Report
--- No concept or definition found.
--- No concept or definition found.
consideration Can't insert record


So moodle is telling me it's importing 23 of 26 entries when there are 189 entries in the file sad

If I open the XML file in Internet Explorer it reports a syntax error part way down, but doesn't give any meaningful information on exactly where in the file it is.

Opening the XML file in Firefox (which is usually good for checking valid XML) reports no syntax errors...

The only thing I can think of is that some non-printable characters such as control codes have found their way into the original document, so somehow I need to screen those out...

Will keep working on it.

Regards,
Simon

In reply to Simon Byrnand

Re: Anyone have a script for converting to xml?

by David Fountain -

I suggest you have a look at it in a plain text editor like Notepad, Word can hide a number of gremlins.

After the paste from Word save it as a csv, close it and open in Notepad (ignore any " at this point as they are used to delimit text cells) and this should reveal any strange codes.

In reply to David Fountain

Re: Anyone have a script for converting to xml?

by David Fountain -

Swapping &'s and " s, of course you should replace the &'s first otherwise you will end up with some very strange combinations...eg

& "

could become

&amp &ampquot

instead of

&amp &quot

In reply to David Fountain

Re: Anyone have a script for converting to xml?

by Garry Stokes -
Great spreadsheet, once I worked out I had to run the macro on a Peecee.
sad
In reply to Garry Stokes

Re: Anyone have a script for converting to xml?

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
>... a Peecee

By that, I suppose you mean "a standard computer"? wink

In reply to Garry Stokes

Re: Anyone have a script for converting to xml?

by David Fountain -
Yes, sorry Garry, I am a child of IBM (or should that be clone?thoughtful)
In reply to Simon Byrnand

Re: Anyone have a script for converting to xml?

by Pedro Guevara -
Hi:
I have the same problem with spanish accented characters (á é í ó ú)

If you solve the problem, please let me know
In reply to David Fountain

Re: Anyone have a script for converting to xml?

by John-Ross Cromer -
Thank you 2.5 years from the original thread! I am quick at work building a continuing education website for the solar industry www.greencitysolar.us. We are starting tonight in case anyone wants to watch it grow / help out. This is saving us hours and hours of solar glossary generation.
In reply to David Fountain

Re: Anyone have a script for converting to xml?

by Liz B -

Thanks Dave!  Worked a treat.

In reply to David Fountain

Re: Anyone have a script for converting to xml?

by Pam Blasius -


David, worked like a charm.  You saved me hours of data entry time.  Thank you!