额外的新线条和空间我怎样才能改变我的XML的外观例如从为什么元素蟒蛇树中添加XML
<root>
<elem1>
<value>
122
</value>
<text>
This_is_just_a_text
</text>
</elem1>
<elem1>
<value>
122
</value>
<text>
This_is_just_a_text
</text>
</elem1>
</root>
的东西看起来像:
<root>
<elem1>
<value>122</value>
<text>This_is_just_a_text</text>
</elem1>
<elem1>
<value>122</value>
<text>This_is_just_a_text</text>
</elem1>
</root>
我只是想知道是什么原因发生?顺便说一下,下面的方法/函数用于添加缩进!
def prettify(elem):
"""
Return a pretty-printed XML string for the Element.
"""
rough_string = ET.tostring(elem, 'utf-8')
reparsed = minidom.parseString(rough_string)
return reparsed.toprettyxml(indent="\t")
当子元素是要打印的元素在一行叶 - 这是你的美感或者是什么原因?如果文本很长,你永远不会看到结束标记。使用相同的缩进级别打开和关闭一个元素下方的标记完全可以理解。拿它像一个男人或给出任何理由为什么要改变外观;) – rebeling
可能相关:http://stackoverflow.com/questions/3310614/remove-whitespaces-in-xml-string –