xml_Utils.py 文件源码

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

项目:warriorframework 作者: warriorframework 项目源码 文件源码
def getChildTextbyOtherChild (datafile, pnode, cnode, cvalue, rnode):
    """
    Searches XML file for the parent node. Finds the 1st child node and checks its value
    if value is a match, then search for second child and return its value
    datafile = xml file searched
    pnode = parent node
    cnode = child node
    cvalue = child node value
    rnode = reference node or False if doesn't exist
    """
    tree = ElementTree.parse(datafile)
    root = tree.getroot()
    rnodev = False

    for node in root.findall(pnode):
        value = node.find(cnode).text
        if value == cvalue:
            # print_debug("-D- rnode: '%s'" % rnode)
            if node.find(rnode) is not None:
                rnodev = node.find(rnode).text
                break
    return rnodev
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号