xml_Utils.py 文件源码

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

项目:warriorframework 作者: warriorframework 项目源码 文件源码
def getElementWithTagAttribValueMatch(start, tag, attrib, value):
    """
    When start is an xml datafile, it finds the root and first element with:
        tag, attrib, value.
    Or when it's an xml element, it finds the first child element with:
        tag, attrib, value.
    If there is not a match, it returns False.
    """
    node = False
    if isinstance(start, (file, str)):
        # check if file exist here
        if file_Utils.fileExists(start):
            node = ElementTree.parse(start).getroot()
        else:
            print_warning('The file={0} is not found.'.format(start))
    elif isinstance(start, ElementTree.Element):
        node = start
    if node is not False and node is not None:
        elementName = ".//%s[@%s='%s']" % (tag, attrib, value)
        element = node.find(elementName)
    else:
        element = node
    return element
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号