0

I would like to add a list of equations in a CSV to an xml doc for importing into moodle lms. Is there a way i can do this with python. along the lines of a mail merge. I have tried with libre office but the xml gets changed i have tried the following links and more. thanks

Replace Marker with XML text with BASH Add to origonal xml file from for loop in python Replacing XML element in Python

1 Answers1

0

Answering my own Question? i found that templating would provide the answer, and used pystache as it seemed really simple. Finally

import pystache
txt = open('pystachetempl.xml', 'r').read()
doc = open('results.xml', 'wb')

doc.write(pystache.render(txt, {
  "questionname": "expon frac neg",
  "latexquestion1": "frac{3{x}^{-3}}{{(3x)}^{2}}",
  "tans1": "1/(3*x^5)"
   }).encode('utf-8'))

i wasn't able to read the context from file and had to use the replacement values in the code to get it to work.