python批量修改xml文件內容


import xml.etree.ElementTree as ET
def change_xml(xml_path):
    filelist = os.listdir(xml_path)
    print(filelist)
    # 打開xml文檔
    for xmlfile in filelist:
        doc = ET.parse(xml_path+xmlfile)
        root = doc.getroot()
        sub1 = root.find('filename')  #找到filename標簽,
        sub1.text = xmlfile     #修改標簽內容
        
        doc.write(xml_path+xmlfile)   #保存修改
 
change_xml('/Annotations1/') //xml文件路徑

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM