im at work and trying to make a script which adds only selected xml from to a new created xml file(from a csv). Here is what I got so far..Apologize for formatting
Create a script from a csv - works:
if len(sys.argv) != 2:
os._exit(1)
path=sys.argv[1] # get folder as a command line argument
os.chdir(path)
csvFiles = [f for f in os.listdir('.') if f.endswith('.csv') or f.endswith('.CSV')]
for csvFile in csvFiles:
xmlFile = csvFile[:-4] + '.xml'
etc.. (xml is created after my script from a csv..) Now I want to append from an xml in the same directory to the end of the newly created xml file..
Append xml into new script -failing!
xmlFiles = [x for x in os.listdir('.') if x.endswith('.xml') or f.endswith('.XML')]
for xmlFile in xmlFiles:
tree = ET.parse(xmlFile)
Meta = tree.getroot()
a = Meta.find('Speaker')
a1 = Meta.find('Device')
b = ET.SubElement(a, 'speaker')
c = ET.SubElement(b, 'device')
for i in range(len(tags)):
tags[i] = tags[i].replace(' ', '_')
else:
xmlData.write('<row>' + "\n")
for i in range(len(tags)):
xmlData.write(' ' + '<' + tags[i] + '>' \
+ row[i] + '</' + tags[i] + '>' + "\n")
xmlData.write('</row>' + "\n")
rowNum +=1
xmlData.write('</csv_data>' + "\n")
xmlData.close()
print ET.tostring(Meta)
Also if there is a better, different approach and refernce I would be happy :) Thanks