def format(file_metrics, build_metrics):
    def indent(elem, level=0):
        i = "\n" + level*"  "
        if len(elem):
            if not elem.text or not elem.text.strip():
                elem.text = i + "  "
            if not elem.tail or not elem.tail.strip():
                elem.tail = i
            for elem in elem:
                indent(elem, level+1)
            if not elem.tail or not elem.tail.strip():
                elem.tail = i
        else:
            if level and (not elem.tail or not elem.tail.strip()):
                elem.tail = i
    root = ET.Element('metrics')
    files = ET.Element('files')
    root.append(files)
    for key in file_metrics.keys():
        tmp_file = ET.SubElement(files, "file",
                                 {'name': key, 'language': file_metrics[key]['language']})
        for name in file_metrics[key].keys():
            if name == 'language':
                continue
            tmp_metric = ET.SubElement(tmp_file, "metric",
                                       {'name': name, 'value': str(file_metrics[key][name])})
    if build_metrics:
        build = ET.Element('build')
        root.append(build)
    indent(root)
    if PY3:
        body = ET.tostring(root, encoding='unicode')
    else:
        body = ET.tostring(root)
    return body