即时工作并尝试制作一个脚本,该脚本仅将选定的xml添加到新创建的xml文件中(来自csv)。这是我到目前为止所做的..为格式化而道歉
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'
等。 (我的脚本来自csv后创建了xml ..) 现在我想从同一目录中的xml追加到新创建的xml文件的末尾..
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)
如果有更好的,不同的方法和参考,我会很高兴:)谢谢