def patch_minidom_writexml():

    import sys
    if sys.version_info >= (2, 7, 3):
        return

    import xml.dom.minidom as md

    def element_writexml(self, writer, indent="", addindent="", newl=""):
        # indent = current indentation
        # addindent = indentation to add to higher levels
        # newl = newline string
        writer.write(indent + "<" + self.tagName)

        attrs = self._get_attributes()
        a_names = list(attrs.keys())
        a_names.sort()

        for a_name in a_names:
            writer.write(" %s=\"" % a_name)
            md._write_data(writer, attrs[a_name].value)
            writer.write("\"")
        if self.childNodes:
            writer.write(">")
            if (len(self.childNodes) == 1
                    and self.childNodes[0].nodeType == md.Node.TEXT_NODE):
                self.childNodes[0].writexml(writer, '', '', '')
            else:
                writer.write(newl)
                for node in self.childNodes:
                    node.writexml(writer, indent + addindent, addindent, newl)
                writer.write(indent)
            writer.write("</%s>%s" % (self.tagName, newl))
        else:
            writer.write("/>%s" % (newl))

    md.Element.writexml = element_writexml

    def text_writexml(self, writer, indent="", addindent="", newl=""):
        md._write_data(writer, "%s%s%s" % (indent, self.data, newl))

    md.Text.writexml = text_writexml
Patch for xml.dom.minidom toprettyxml bug with whitespaces around text
dataset/ETHPy150Open openstack/sahara/sahara/utils/patches.py/patch_minidom_writexml