怎么样:
from xml.etree import ElementTree as ETxml = '<root>start here<child1>some text<sub1/>here</child1>and<child2>here as well<sub2/><sub3/></child2>end here</root>'root = ET.fromstring(xml)def content(tag): return tag.text + ''.join(ET.tostring(e) for e in tag)print content(root)print content(root.find('child2'))导致:
start here<child1>some text<sub1 />here</child1>and<child2>here as well<sub2 /><sub3 /></child2>end herehere as well<sub2 /><sub3 />



