将xml文件中图片格式修改为jpg:
1、只需要修改path路径,到*.xml所在的文件夹,运行之后会把xml
修改为.jpg。
import osimport os.pathimport xml.dom.minidompath = r'D:\Desktop\ABBA\xml'files = os.listdir(path) # 得到文件夹下所有文件名称s = []count = 0for xmlFile in files: # 遍历文件夹if not os.path.isdir(xmlFile): # 判断是否是文件夹,不是文件夹才打开name1 = xmlFile.split('.')[0]dom = xml.dom.minidom.parse(path + '\\' + xmlFile)root = dom.documentElementnewfolder = root.getElementsByTagName('folder')newpath = root.getElementsByTagName('path')newfilename = root.getElementsByTagName('filename')# newfolder[0].firstChild.data = 'VOCdevkit\VOC\JPEGImages'# newpath[0].firstChild.data = 'VOCdevkit\VOC\JPEGImages' + '\\' + name1 + '.jpg'newfilename[0].firstChild.data = name1 + '.jpg'with open(os.path.join(path, xmlFile), 'w') as fh:dom.writexml(fh)print('写入name/pose OK!')count = count + 1