Unable to iterate through child tags within a child tag
have tried to find all child tags through root.iter() and iterate the same. however the output is not generated in the hierarchy of the tags
for child in root.iter():
child_tag = child.tag
for child in root.findall('.//' + child_tag):
txt = "tag1/" + "tag2/" + str(child_tag) + "/" + str(child)
print(txt)
Expected output:
tag1
tag1/tag2
tag1/tag2/tag3
tag1/tag2/tag3/tag4
tag1/tag2/tag3/tag5
tag1/tag2/tag3/tag5/tag6
xml file details:
<tag1>
<tag2>
<tag3>
<tag4> </tag4>
<tag5>
<tag6> </tag6>
</tag5>
</tag3>
</tag2>
</tag1>
Output received:
tag1
tag1/tag2
tag1/tag2/tag3
tag1/tag2/tag3/tag4
tag1/tag2/tag3/tag5
tag1/tag2/tag5/tag6
--- not as per hierarchy