+def elm2xml(xelm):
+ """Return the unparsed form of the element"""
+ res = '<{}'.format(xelm.tag)
+ for key in xelm.keys():
+ res += ' {}="{}"'.format(key, xelm.attrib[key])
+ res += ">"
+ if xelm.text is not None: # Text before the first child
+ res += xelm.text
+ for i in xelm.getchildren(): # serialize every subtag
+ res += elm2xml(i)
+ if xelm.tail is not None: # Text after last child
+ res += xelm.tail
+ res += '</{}>'.format(xelm.tag)
+ return res
+def elm2txt(xelm):
+ """Return the content of the element, with all tags removed. Only the text remains"""
+ res = ''
+ if xelm.text is not None: # Text before the first child
+ res += xelm.text
+ for i in xelm.getchildren(): # serialize every subtag
+ res += elm2txt(i)
+ if xelm.tail is not None: # Text after last child
+ res += xelm.tail
+ return res
+