代码改变世界

XML文件解析

2016-05-05 11:11  xzh—dream  阅读(157)  评论(0编辑  收藏  举报
 
#resthread.xml
<?xml version='1.0' encoding='UTF-8'?>
<limit>
    <data name='thread_nu' value='3' />
</limit>
from xml.dom.minidom

def getConfig():
    xml_path = resthread.xml
    config = {}
    root = xml.dom.minidom.parse(xml_path)
    xml_root = root.documentElement
    nodes = xml_root.getElementsByTagName('data')
    for node in nodes:
        config[node.getAttribute('name')] = node.getAttribute('value')
    return config

def threadNu():
    config = {}
    config = getConfig()
    nu = config['thread_nu']