Is there an equivalent to the c# XmlNode.InnerText
Property in Python?
If not, is there a straightforward way to implement it in Python? I thought I found something here, but it seems to concatenate the values of the node and child nodes in the wron开发者_运维技巧g order.
Here's a little recursive function that works with ElementTree:
def innertext(tag):
return (tag.text or '') + ''.join(innertext(e) for e in tag) + (tag.tail or '')
Example usage:
import xml.etree.ElementTree as ET
root = ET.parse('somefile.xml').getroot()
print innertext(root)
精彩评论