Python 解析XML
解析
import xml.dom.minidom
class ReadConf:
def read(self):
# 打开xml文档
dom = xml.dom.minidom.parse('conf.xml')
得到文档元素对象
root = dom.documentElement
conf_nodes = root.getElementsByTagName('conf')
conf_dict = {}
for conf_node in conf_nodes:
conf_dict[conf_node.getElementsByTagName('name')[0].firstChild.data] =
conf_node.getElementsByTagName('value')[
0].firstChild.data
return conf_dict
岑忠满的博客新站点
http://cenzm.xyz

浙公网安备 33010602011771号