import os
import xml.etree.ElementTree as ET
def changelabelname(inputpath):
listdir = os.listdir(inputpath)
for file in listdir:
if file.endswith('xml'):
file = os.path.join(inputpath,file)
tree = ET.parse(file)
root = tree.getroot()
for object1 in root.findall('object'):
for sku in object1.findall('name'):
if (sku.text == 'no trousers'):
sku.text = 'no safe trousers'
tree.write(file,encoding='utf-8')
else:
pass
else:
pass
if __name__ == '__main__':
inputpath = 'H:/lujun/xml-lujun'
changelabelname(inputpath)