def METHOD_NAME(self, tree, pretty_print=True, encoding='iso-8859-1'):
    """ Serialize a tree to an XML string. Also adds the ``schemaLocations``
        attribute to the root node.
    """
    schema_locations = self.get_schema_locations()
    # Both Element and ElementTree have to be supported.
    root = tree if hasattr(tree, 'attrib') else tree.getroot()
    root.attrib[ns_xsi("schemaLocation")] = " ".join(
        "%s %s" % (uri, loc) for uri, loc in schema_locations.items()
    )
    return etree.tostring(
        tree, pretty_print=pretty_print, encoding=encoding
    )