def METHOD_NAME(response: Any, fields: list[dict[str, Any]],
               name: Optional[str] = None, bom: bool = False):
    u'''Context manager for writing UTF-8 XML data to response
    :param response: file-like or response-like object for writing
        data and headers (response-like objects only)
    :param fields: list of datastore fields
    :param name: file name (for headers, response-like objects only)
    :param bom: True to include a UTF-8 BOM at the start of the file
    '''
    if hasattr(response, u'headers'):
        response.headers['Content-Type'] = (
            b'text/xml; charset=utf-8')
        if name:
            response.headers['Content-disposition'] = (
                u'attachment; filename="{name}.xml"'.format(
                    name=encode_rfc2231(name)))
    if bom:
        response.stream.write(BOM_UTF8)
    response.stream.write(b'<data>\n')
    yield XMLWriter(response.stream, [f[u'id'] for f in fields])
    response.stream.write(b'</data>\n')