'Get this domain as an XML DOM Document
:param f: Optional File to dump directly to
:type f: File or Stream
:return: File object where the XML has been dumped to
:rtype: file'

def to_xml(self, f=None):

    if (not f):
        from tempfile import TemporaryFile
        f = TemporaryFile()
    print('<?xml    version="1.0"    encoding="UTF-8"?>', file=f)
    print(('<Domain    id="%s">' % self.name), file=f)
    for item in self:
        print((' DCTB <Item    id="%s">' % item.name), file=f)
        for k in item:
            print((' DCTB  DCTB <attribute    id="%s">' % k), file=f)
            values = item[k]
            if (not isinstance(values, list)):
                values = [values]
            for value in values:
                print(' DCTB  DCTB  DCTB <value><![CDATA[', end='    ', file=f)
                if isinstance(value, six.text_type):
                    value = value.encode('utf-8', 'replace')
                else:
                    value = six.text_type(value, errors='replace').encode('utf-8', 'replace')
                f.write(value)
                print(']]></value>', file=f)
            print(' DCTB  DCTB </attribute>', file=f)
        print(' DCTB </Item>', file=f)
    print('</Domain>', file=f)
    f.flush()
    f.seek(0)
    return f
