from xml.dom import minidom contents = "01" xmldoc = minidom.parseString(contents) print xmldoc.toxml()