'Write to an XML file.
Parameters
fd : str path or writable file-like object
Where to write the file.
compressed : bool, optional
When `True`, write to a gzip-compressed file.  (Default:
`False`)
tabledata_format : str, optional
Override the format of the table(s) data to write.  Must
be one of ``tabledata`` (text representation), ``binary`` or
``binary2``.  By default, use the format that was specified
in each `Table` object as it was created or read in.  See
:ref:`votable-serialization`.'

def to_xml(self, fd, compressed=False, tabledata_format=None, _debug_python_based_parser=False, _astropy_version=None):

    if (tabledata_format is not None):
        if (tabledata_format.lower() not in (u'tabledata', u'binary', u'binary2')):
            raise ValueError(u"Unknown    format    type    '{0}'".format(format))
    kwargs = {u'version': self.version, u'version_1_1_or_later': (util.version_compare(self.version, u'1.1') >= 0), u'version_1_2_or_later': (util.version_compare(self.version, u'1.2') >= 0), u'version_1_3_or_later': (util.version_compare(self.version, u'1.3') >= 0), u'tabledata_format': tabledata_format, u'_debug_python_based_parser': _debug_python_based_parser, u'_group_number': 1}
    with util.convert_to_writable_filelike(fd, compressed=compressed) as fd:
        w = XMLWriter(fd)
        version = self.version
        if (_astropy_version is None):
            lib_version = astropy_version
        else:
            lib_version = _astropy_version
        xml_header = u'\n<?xml    version="1.0"    encoding="utf-8"?>\n<!--    Produced    with    astropy.io.votable    version    {lib_version}\n                    http://www.astropy.org/    -->\n'
        w.write(xml_header.lstrip().format(**locals()))
        with w.tag(u'VOTABLE', {u'version': version, u'xmlns:xsi': u'http://www.w3.org/2001/XMLSchema-instance', u'xsi:noNamespaceSchemaLocation': u'http://www.ivoa.net/xml/VOTable/v{}'.format(version), u'xmlns': u'http://www.ivoa.net/xml/VOTable/v{}'.format(version)}):
            if (self.description is not None):
                w.element(u'DESCRIPTION', self.description, wrap=True)
            element_sets = [self.coordinate_systems, self.params, self.infos, self.resources]
            if kwargs[u'version_1_2_or_later']:
                element_sets[0] = self.groups
            for element_set in element_sets:
                for element in element_set:
                    element.to_xml(w, **kwargs)
