In Python 2.6 using ElementTree, what\'s a good way to fetch the XML (as a string) inside a particular element, like what you can do in HTML and javascript with innerHTML? <
How about:
from xml.etree import ElementTree as ET
xml = 'start heresome text here andhere as well end here '
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'))
Resulting in:
start heresome text here andhere as well end here
here as well