Reading dynamic xml using element tree

Environment: Windows, Python, wxpython, and the Element tree as an XML parser.

I am developing a stand alone where it reads xml and creates a tree. My application reads xml and creates a tree, but when xml changes next time (when DEPTH from xml increases - I mean when two children are added). Application is not readable (Logic failed :()

For example, I wrote logic that can read any xml that has a depth of 5. But when it reads xml with a depth of more than 5, it fails. Please let me know how to read xml, the depth of which is dynamic.

+3
source share
1 answer

, - :

def recurse_tree(node):
    tree = {}
    for element in node:
        name = element.get('name')
        tree[name] = recurse_tree(element)
    if tree:
        return tree
    else:
        return 'No children.'

"". , .

+2

Source: https://habr.com/ru/post/1771186/


All Articles