python解析xml

import xml.dom.minidom

# 打开xxx.xml文档
xml_fail = xml.dom.minidom.parse(xmlpath)
# 得到文档元素对象
root = xml_fail.documentElement

# 根据标签为xxx的信息,获取所有标签为xxx的信息

xxx_info= model_res.getElementsByTagName("xxx") # 将xml中按照xxx保存到xxx_info
# 根据xxx_info得到属性为aaa的信息
xxx_info.getAttribute("aaa")


# 生成kkk.xml文件
# with open(os.path.join(path,'kkk.xml'), 'w',encoding="utf-8") as xw:

# xw.write('\n')
#     xw.write('\n')
#     xw.write("{:>2}{}".format(" ", '\n'))
#     xw.write("{:>2}{}".format(" ", '\n'))
#     xw.write('')


转载于:https://www.cnblogs.com/AEBOKE/p/11243446.html

你可能感兴趣的:(python解析xml)