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