from xml.dom.minidom import parse, parseString document = """ """ print document dom = parseString(document) xml_res = dom.toxml() print xml_res