I wrote a method that seems to work correctly to recursively go throug a xml. But it returns a None instead of a string. I figured out that it has something to do with the way I call the recursive function but can't figure out how to make it work. The print("returning: {}".format(path) prints the correct result but the returned value is None.
Here is my code:
# retrieves the path of an given xml-node
def getParentValueAndId(self,node, path):
actual_node = node.getparent().getparent().getparent().find(self.openEHR_prefix + "rm_attribute_name")
node_id = node.getparent().getparent().find(self.openEHR_prefix + "node_id").text
if (path == "value" and node_id is not None):
path = "/{}[{}]/{}".format(actual_node.text, node_id, path)
try:
self.getParentValueAndId(actual_node, path)
except:
pass
elif not (node_id is None):
path = "/{}[{}]{}".format(actual_node.text, node_id, path)
try:
self.getParentValueAndId(actual_node, path)
except:
print("returning: {}".format(path))
return path
else:
try:
self.getParentValueAndId(actual_node, path)
except:
pass