import lxml.etree class Moodle: def __init__(self,string_xml): self.version="" self.name="" self.description="" print "Reading Moodle file" root = lxml.etree.fromstring(string_xml) for snode in root: if snode.tag=="INFO": for inode in snode: if inode.tag=="BACKUP_VERSION": self.version = inode.text if snode.tag=="COURSE": for cnode in snode: if cnode.tag=="HEADER": for qnode in cnode: if qnode.tag=="FULLNAME": self.name=qnode.text if qnode.tag=="SUMMARY": self.description=qnode.text