如何获取XML文档的所有文本内容,作为单个字符串-like this Ruby/hpricot example但使用Python.
我想用一个空格替换XML标签.
解决方法:
你问了lxml:
reslist = list(root.iter())
result = ' '.join([element.text for element in reslist])
要么:
result = ''
for element in root.iter():
result += element.text + ' '
result = result[:-1] # Remove trailing space