python读写xml文件

使用方法见:https://www.cnblogs.com/Zhouzg-2018/p/9926048.html

from  xml.dom.minidom import Document
import xml.etree.ElementTree as ET





#
# def writeXml(imgPath='',save_path="/home/gui/newXml.xml"):
#
#     #先简单实现下,考虑一个目标
#     doc=Document()
#     root=doc.createElement('annotation')
#     doc.appendChild(root)
#
#     node_1=doc.createElement('folder')
#     txt_1=doc.createTextNode('ImageSets')
#     node_1.appendChild(txt_1)
#     root.appendChild(node_1)
#
#     node_2=doc.createElement('name')
#     txt_2=doc.createTextNode('0001.jpg')
#     node_2.appendChild(txt_2)
#     root.appendChild(node_2)
#
#     node_3=doc.createElement('path')
#     txt_3=doc.createTextNode('/home/gui/mot2015/0001.jpg')
#     node_3.appendChild(txt_3)
#     root.appendChild(node_3)
#
#     node_4=doc.createElement('size')
#     node_41=doc.createElement('width')
#     txt_41=doc.createTextNode('100')
#     node_41.appendChild(txt_41)
#     node_42=doc.createElement('height')
#     txt_42=doc.createTextNode('100')
#     node_42.appendChild(txt_42)
#     node_4.appendChild(node_41)
#     node_4.appendChild(node_42)
#     root.appendChild(node_4)
#
#     node_object=doc.createElement('object')
#     node_5=doc.createElement('Xmin')
#     txt_5=doc.createTextNode('1')
#     node_5.appendChild(txt_5)
#     node_object.appendChild(node_5)
#     node_6=doc.createElement('Ymin')
#     txt_6=doc.createTextNode('1')
#     node_6.appendChild(txt_6)
#     node_object.appendChild(node_6)
#     node_7=doc.createElement('Xmax')
#     txt_7=doc.createTextNode('1')
#     node_7.appendChild(txt_7)
#     node_object.appendChild(node_7)
#     node_8=doc.createElement('Ymax')
#     txt_8=doc.createTextNode('1')
#     node_8.appendChild(txt_8)
#     node_object.appendChild(node_8)
#     root.appendChild(node_object)
#
#     with open(save_path,'w')as outFile:
#         doc.writexml(outFile,indent='\t', newl='\n', addindent='\t', encoding='gbk')
#
#         outFile.close()
#
# writeXml()


def generate(xmlFile=""):
    root
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值