如何删除Python 2.6中XML字符串中的空格和换行符?我尝试了以下软件包:删除XML字符串中的空格
etree:这个片段可以保持原有的空格:
xmlStr = '''<root>
<head></head>
<content></content>
</root>'''
xmlElement = xml.etree.ElementTree.XML(xmlStr)
xmlStr = xml.etree.ElementTree.tostring(xmlElement, 'UTF-8')
print xmlStr
我不能使用Python 2.7,其将提供method
参数。
minidom命名:一样的:
xmlDocument = xml.dom.minidom.parseString(xmlStr)
xmlStr = xmlDocument.toprettyxml(indent='', newl='', encoding='UTF-8')
这可能有助于使用LXML删除从文本节点http://stackoverflow.com所有空行和空白频段/ a/19396130/973699 – DevC 2013-10-16 06:09:42