def record2marcxml(record):
schema_name = _get_schema_name(record)<EOL>if schema_name == '<STR_LIT>':<EOL><INDENT>marcjson = hep2marc.do(record)<EOL><DEDENT>elif schema_name == '<STR_LIT>':<EOL><INDENT>marcjson = hepnames2marc.do(record)<EOL><DEDENT>else:<EOL><INDENT>raise NotImplementedError(u'<STR_LIT>'.format(schema_name))<EOL><DEDENT>record = RECORD()<EOL>for key, values in sorted(iteritems(marcjson)):<EOL><INDENT>tag, ind1, ind2 = _parse_key(key)<EOL>if _is_controlfield(tag, ind1, ind2):<EOL><INDENT>value = force_single_element(values)<EOL>if not isinstance(value, text_type):<EOL><INDENT>value = text_type(value)<EOL><DEDENT>record.append(CONTROLFIELD(_strip_invalid_chars_for_xml(value), {'<STR_LIT>': tag}))<EOL><DEDENT>else:<EOL><INDENT>for value in force_list(values):<EOL><INDENT>datafield = DATAFIELD({'<STR_LIT>': tag, '<STR_LIT>': ind1, '<STR_LIT>': ind2})<EOL>for code, els in sorted(iteritems(value)):<EOL><INDENT>for el in force_list(els):<EOL><INDENT>if not isinstance(el, text_type):<EOL><INDENT>el = text_type(el)<EOL><DEDENT>datafield.append(SUBFIELD(_strip_invalid_chars_for_xml(el), {'<STR_LIT:code>': code}))<EOL><DEDENT><DEDENT>record.append(datafield)<EOL><DEDENT><DEDENT><DEDENT>return tostring(record, encoding='<STR_LIT:utf8>', pretty_print=True)<EOL>
Convert a JSON record to a MARCXML string.

    Deduces which set of rules to use by parsing the ``$schema`` key, as
    it unequivocally determines which kind of record we have.

    Args:
        record(dict): a JSON record.

    Returns:
        str: a MARCXML string converted from the record.