from xml.dom import minidom fsock = open('binary.xml') xmldoc = minidom.parse(fsock) fsock.close() print xmldoc.toxml()