xml_Utils.py 文件源码

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

项目:warriorframework 作者: warriorframework 项目源码 文件源码
def getConfigElementTextWithSpecificXpath(datafile, xpath):
    """
    This method takes an xml document as input and finds the first sub element (parent/children)
    containing specified xpath which should be a filepath to a netconf config file

    Returns the element text attribute

    Arguments:
    parent = parent element
    xpath = a valid xml path value as supported by python, refer https://docs.python.org/2/library/xml.etree.elementtree.html
    """
    root = ElementTree.parse(datafile).getroot()
    elem1 = root.find(xpath).text

    elem2_root = ElementTree.parse(elem1)
    elem2 = elem2_root.find('config')
    elem2_string = ElementTree.tostring(elem2)
    return elem2_string
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号