def getChildAttributebyParentTag (datafile, pnode, cnode, cattrib):
"""Find the attribute in child node by traversing through the parent node
in the given file
datafile = xml file searched
pnode = parent node
cnode = child node
cattrob = child node attrib
"""
tree = ElementTree.parse(datafile)
root = tree.getroot()
node = root.find(pnode)
if node is not None:
child = node.find(cnode)
if child is not None:
value = child.get(cattrib)
return value
else:
# print_info("could not find cnode under the given pnode")
return False
else:
# print_info("could not find pnode in the provided file")
return False
评论列表
文章目录