79074415

Date: 2024-10-10 12:34:43
Score: 2.5
Natty:
Report link

An Element object has two attributes of interest here:

So all you need is this:

import xml.etree.ElementTree as ET
root = ET.parse('sample.xml').getroot()
for child in root:
    output = child.text
    for grandchild in child:
        output += ET.tostring(grandchild, encoding="unicode")
    print(output)

Output is:

My name is <b>Wrufesh</b>. What is yours?
Reasons:
  • Blacklisted phrase (1): What is your
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Ends in question mark (2):
  • Low reputation (0.5):
Posted by: Alex Ball