Skip to content Skip to sidebar Skip to footer

Fetching The Path( From Root Node ) For All The Leaf Nodes?

My python script reads a XML file, to give the Folder Structure. My XML file: ): name = e.attrib['name'] # TODO: checking whether this is the leaf node # perhaps there are better ways if len(e) > 0: runningname += f'/{name}' children = [walk(c, runningname) for c in e if e.tag == 'serverfiles'] return {'name': name, 'children': children} if children else {'name': name, 'path': runningname} file = ET.parse(r'r.xml') r = file.getroot() s = walk(r) pprint(s)

Post a Comment for "Fetching The Path( From Root Node ) For All The Leaf Nodes?"