code: def create_asap_annotations_xml(json_data, loglevel="INFO"):
      logger.setLevel(loglevel.upper())
  
      total_count = 0
      label_xml = tempfile.NamedTemporaryFile(suffix=".xml").name
  
      name = json_data["name"]
      description = json_data["description"]
      model = json_data["model"]
      location = json_data.get("location", (0, 0, 0, 0))
      location = location if location else (0, 0, 0, 0)
      size = json_data.get("size", (0, 0))
      size = size if size else (0, 0)
  
      with open(label_xml, "w") as fp:
          fp.write('<?xml version="1.0"?>\n')
          fp.write("<ASAP_Annotations>\n")
          fp.write(
              '  <Annotations Name="{}" Description="{}" Model="{}" X="{}" Y="{}" W="{}" H="{}">\n'.format(
                  name,
                  description,
                  model,
                  location[0],
                  location[1],
                  size[0],
                  size[1],
              )
          )
  
          labels = {}
          for tid, res in enumerate(json_data["annotations"]):
              logger.debug(f"Adding annotations for tile: {tid}")
              if not res:
                  continue
  
              annotation = res.get("annotation")
              if not annotation:
                  continue
  
              logger.info(f"Annotation keys: {annotation.keys()}")
              color_map = annotation.get("labels")
              elements = annotation.get("elements", [])
              for element in elements:
                  label = element["label"]
                  color = to_hex(color_map.get(label))
  
                  logger.info(
                      f"Adding Contours for label: {label}; color: {color}; color_map: {color_map}"
                  )
                  labels[label] = color
  
                  contours = element["contours"]
                  for contour in contours:
                      fp.write(
                          f'    <Annotation Name="{label}" Type="Polygon" PartOfGroup="{label}" Color="{color}">\n'
                      )
                      fp.write("      <Coordinates>\n")
                      for pcount, point in enumerate(contour):
                          fp.write(
                              f'        <Coordinate Order="{pcount}" X="{point[0]}" Y="{point[1]}" />\n'
                          )
                      fp.write("      </Coordinates>\n")
                      fp.write("    </Annotation>\n")
                      total_count += 1
          fp.write("  </Annotations>\n")
  
          fp.write("  <AnnotationGroups>\n")
          for label, color in labels.items():
              fp.write(
                  f'    <Group Name="{label}" PartOfGroup="None" Color="{color}">\n'
              )
              fp.write("      <Attributes />\n")
              fp.write("    </Group>\n")
          fp.write("  </AnnotationGroups>\n")
          fp.write("</ASAP_Annotations>\n")
  
      logger.info(f"Total Annotations: {total_count}")
      return label_xml, total_count
  
imports: import json
  import logging
  import tempfile
  from monailabel.utils.others.label_colors import to_hex, to_rgb
label_desc: Use image node_id 2 for calling a global function with example usage: create_asap_annotations_xml(json_data, loglevel) and returns: label_xml,  total_count