Refinements

This commit is contained in:
Ircama 2024-07-07 15:36:36 +02:00
parent fcd0c41076
commit 64d7a915c2

View file

@ -27,12 +27,15 @@ def text_to_dict(text):
def traverse_data(element, depth=0):
indent = ' ' * depth
if element.tag:
print(indent + element.tag)
if element.attrib:
print(indent + ' Attributes:', element.attrib)
if element.text and element.text.strip():
print(indent + ' Text:', element.text.strip())
if element.tag and not element.attrib and element.text and element.text.strip():
print(indent + element.tag + " = " + element.text)
else:
if element.tag:
print(indent + element.tag + ":")
if element.attrib:
print(indent + ' Attributes:', element.attrib)
if element.text and element.text.strip():
print(indent + ' Text:', element.text.strip())
# Recursively traverse the children
for child in element: