Wisst ihr eine Alternative?
Hier ein minimales Beispiel des Codes, ich hoffe er reicht, um den Kontext zu verstehen:
Code: Alles auswählen
def dict_to_xml(root, d, valueresolver=lambda x: x):
""" Recursively translates a dictionary of xpath-like expressions as keys
and text or substructure(s) as values into XML
"""
if isinstance(d, str):
root.text = d
return
elif isinstance(d, etree._Element):
root.append(d)
return
else:
pass
# more code, e.g. to process the special-syntax keys that represent not only a single element,
# but elements that can be nested in other elements to be created if needed as well.
# recurse into dictionary and list instances as values