xml_Utils.py 文件源码

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

项目:warriorframework 作者: warriorframework 项目源码 文件源码
def getElementsListWithTagAttribValueMatch(datafile, tag, attrib, value):
    """
    This method takes an xml document as input and finds all the sub elements (parent/children)
    containing specified tag and an attribute with the specified value.

    Returns a list of matching elements.

    Arguments:
    datafile = input xml file to be parsed.
    tag = tag value of the sub-element(parent/child) to be searched for.
    attrib = attribute name for  the sub-element with above given tag should have.
    value = attribute value that the sub-element with above given tag, attribute should have.
    """
    element_list = []
    root = ElementTree.parse(datafile).getroot()
    for element in root.iterfind(".//%s[@%s='%s']" % (tag, attrib, value)):
        element_list.append(element)
    return element_list
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号