def METHOD_NAME(eo_id, target_dir):
    try:
        wcseo_object = EOxSRectifiedDatasetSeriesRecord.objects.get(eo_id=eo_id)
    except:
        wcseo_object = EOxSRectifiedStitchedMosaicRecord.objects.get(eo_id=eo_id)
    encoder = EOxSNativeEncoder()
    for dataset in wcseo_object.rect_datasets.all():
        md_el = encoder.encodeEOMetadata(dataset.eo_id, dataset.eo_metadata)
        md_filename = "%s.%s" % (os.path.splitext(os.path.basename(dataset.file.path))[0], "xml")
        f = open(os.path.join(target_dir, md_filename), 'w')
        f.write(md_el.toxml())
        f.close()