'Write the XML declaration at the top of the document.'

def __write_dec(self):

    check_encoding_obj = check_encoding.CheckEncoding(bug_handler=self.__bug_handler)
    if (not check_encoding_obj.check_encoding(self.__file, verbose=False)):
        self.__write_obj.write('<?xml    version="1.0"    encoding="US-ASCII"    ?>')
    elif (not check_encoding_obj.check_encoding(self.__file, self.__encoding, verbose=False)):
        self.__write_obj.write('<?xml    version="1.0"    encoding="UTF-8"    ?>')
        self.__convert_utf = True
    else:
        self.__write_obj.write('<?xml    version="1.0"    encoding="US-ASCII"    ?>')
        sys.stderr.write('Bad    RTF    encoding,    revert    to    US-ASCII    chars    and    hope    for    the    best')
        self.__bad_encoding = True
    self.__new_line = 0
    self.__write_new_line()
    if self.__no_dtd:
        pass
    elif self.__dtd_path:
        self.__write_obj.write(('<!DOCTYPE    doc    SYSTEM    "%s">' % self.__dtd_path))
    elif (self.__dtd_path == ''):
        pass
    else:
        self.__write_obj.write(('<!DOCTYPE    doc    PUBLIC    "publicID"    "http://rtf2xml.sourceforge.net/dtd/%s">' % public_dtd))
    self.__new_line = 0
    self.__write_new_line()
