用python读取xml文件的写法举例

原xml文件:

loginError.xml



    RpmsLoginCase
    
    
    

读取xml的py文件:

xmlData.py

# coding:utf-8
import xml.dom.minidom
from config import globalparam

xml_path=globalparam.xml_path

def getXmlData(value):
    dom = xml.dom.minidom.parse(xml_path)
    db = dom.documentElement
    name = db.getElementsByTagName(value)
    nameValue = name[0]
    return nameValue.firstChild.data

def getXmlUser(parent, child):
    dom = xml.dom.minidom.parse(xml_path)
    db = dom.documentElement
    itemlist = db.getElementsByTagName(parent)
    item = itemlist[0]
    return item.getAttribute(child)

if __name__=='__main__':
    print getXmlData('test')
    print  getXmlUser('failLogin1','expected')


你可能感兴趣的:(用python读取xml文件的写法举例)