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
评论列表
文章目录