with open(sys.argv[1], 'rU') as f: reader = csv.DictReader(f) for row in reader: switch_tag = ElementTree.Element('switch') attrs = {'src': ("mp4:soundcheck/{year}/{id}/{file_root_name}_256.mp4".format(**row)),'system-bitrate': '336000',} attrs = {'src': ("mp4:soundcheck/{year}/{id}/{file_root_name}_512.mp4".format(**row)),'system-bitrate': '592000',} attrs = {'src': ("mp4:soundcheck/{year}/{id}/{file_root_name}_768.mp4".format(**row)),'system-bitrate': '848000',} attrs = {'src': ("mp4:soundcheck/{year}/{id}/{file_root_name}_1128.mp4".format(**row)),'system-bitrate': '1208000',} ElementTree.SubElement(switch_tag, 'video', attrs) print minidom.parseString(ElementTree.tostring(switch_tag)).toprettyxml() print minidom.parseString(ElementTree.tostring(switch_tag)).toprettyxml() I want to look like: