I have a CSV with values that I would like to replace inside an XML template. Generating XMLs for each row that have filenames based on data in the same row. These are basically just copies of the template with a find and replace. So far I have gotten the filenames to work correctly but the XML file does not replace its data according to the row instead it only replaces data from row 3, column 10. I'm looking to have it iterate through a range of rows and create new files for each. I'm stumped as to what is going wrong here.
CSV Snippet:
COLUMN_K, COLUMN_L
K02496.ai, Test
K02550.ai, Test
K02686.ai, Test
K02687.ai, Test
Existing XML Template Snippet
<gmd:resourceFormat>
<gmd:MD_Format>
<gmd:name>
<gco:CharacterString>COLUMN_K</gco:CharacterString>
</gmd:name>
Python Code
import csv
exampleFile = open('U:\PROJECTS\Technical Graphics\metadata.csv')
exampleReader = csv.reader(exampleFile)
exampleData = list(exampleReader) #CSV as list
with open('U:\PROJECTS\Technical Graphics\COLUMN_K_edited.xml') as inputfile: #template XML
xml = inputfile.read()
with open('U:\PROJECTS\Technical Graphics\metadata.csv') as csvfile:
for row in reader(csvfile, delimiter=';'):
for i in range(5): #range of 5 rows
xml = xml.replace('COLUMN_K', exampleData[i+3][10])
#Only taking value from row 3, COLUMN_K- Need values from row 3 on
xml = xml.replace('COLUMN_L', exampleData[i+3][11])
#Only taking value from row 3, COLUMN_L- Need values from row 3 on
with open('U:\PROJECTS\Technical Graphics\XXX' + str((exampleData[i+3][10])) + ".xml", 'w') as outputfile:
#Correctly outputs multiple filenames based on COLUMN_K value
outputfile.write(xml) #writes multiple XMLs