xml_Utils.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:warriorframework 作者: warriorframework 项目源码 文件源码
def getChildTextbyParentAttribute (datafile, pnode, patt, pattval, cnode):
    """
    Seraches XML file for the parent node with a specific value. Finds the child node and returns
    its text
    datafile = xml file searched
    pnode = parent node
    patt = parent node attribute
    patval = parent node attribute value
    cnode = child node
    """
    tree = ElementTree.parse(datafile)
    root = tree.getroot()
    value = False
    for node in root.findall(pnode):
        attribute = node.get(patt)
        if attribute == pattval:
            cnode = node.find(cnode)
            if cnode is not None:
                value = cnode.text
            else:
                return None
            break
    return value
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号