import xml
xml_file = xml.dom.minidom.parse("ann_style_14.xml")
RootNode=xml_file.documentElement
subElement1=RootNode.getElementsByTagName("input_scale")
subElement2=RootNode.getElementsByTagName("output_scale")
subElement3=RootNode.getElementsByTagName("inv_output_scale")
subElement4=RootNode.getElementsByTagName("weights")
print(subElement3[0].nodeName)
print(subElement4[0].nodeName)
print(subElement4[0].childNodes[1].nodeName)
print(subElement4[0].childNodes[3].nodeName)
#print(subElement3[0].childNodes[0].data)
#print(subElement4[0].childNodes[1].childNodes[0].data)
#print(subElement4[0].childNodes[3].childNodes[0].data)
subData1=subElement1[0].childNodes[0].data
subData2=subElement2[0].childNodes[0].data
subData3=subElement3[0].childNodes[0].data
subData4=subElement4[0].childNodes[1].childNodes[0].data
subData5=subElement4[0].childNodes[3].childNodes[0].data
fh = open("input_scale.xml", 'w')
fh.write(subData1)
fh.close()
fh = open("output_scale.xml", 'w')
fh.write(subData2)
fh.close()
fh = open("inv_output_scale.xml", 'w')
fh.write(subData3)
fh.close()
fh = open("weights_1.xml", 'w')
fh.write(subData4)
fh.close()
fh = open("weights_2.xml", 'w')
fh.write(subData5)
fh.close()
解析xml文件内容
最新推荐文章于 2022-10-13 22:02:37 发布