I wanted to extract just the grade 0, 1 and 2 cards from a deck to print them for study away from the computer.
I wrote a Python script to parse the XML file and output the question and answer (separated by tab). I open this file with Excel, adjust the font and size, print, cut out, fold over and make my own flashcards. Maybe this script is of some interest to others. Charles http://memoryskills.blogspot.com -------------------------------------------------------------- 1. name the script mxml.py 2. export your XML from Mnemosyne for example to file cards.xml 3. Run the script: python mxml.py cards.xml out.txt 4. Open the file out.txt with Excel (question and answer will be in separate columns) Naturally, you can do anything you want with the script, e.g. ...create LaTeX import codecs, sys import xml.dom.minidom from xml.dom.minidom import Node ############################ def child_tag(node, tagval): L = node.getElementsByTagName(tagval) for node2 in L: val = "" for node3 in node2.childNodes: if node3.nodeType == Node.TEXT_NODE: val += node3.data return val ################################################ from sys import * argc = len(argv) if argc < 2: print "Syntax is %s infile.xml {OUTFILE.TXT}" % argv[0] sys.exit(1) outfile = "outfile.txt" # default output file name if argc == 3: outfile = argv[2] f = codecs.open(argv[1], 'r', encoding = 'utf-8') of = codecs.open(outfile, 'w', encoding = 'utf-8') u = f.read() doc = xml.dom.minidom.parseString( u.encode("utf-8")) ctr = 0 for node in doc.getElementsByTagName("item"): # Retrieve attributes from the <item> tage grade = node.getAttribute("gr") ease = node.getAttribute("a") ac_rp = node.getAttribute("ac_rp") rt_rp = node.getAttribute("rt_rp") # Retrieve the Question and Answer question = child_tag(node, "Q") category = child_tag(node, "cat") answer = child_tag(node, "A") # Output cards with grades 0, 1, 2 if int(grade) < 3: of.write("%s\t%s\t%s\n" % (grade, question, answer)) ctr += 1 of.close() print ctr," items written to %s" % outfile --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "mnemosyne-proj-users" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/mnemosyne-proj-users?hl=en -~----------~----~----~----~------~----~------~--~---
