我有以下代碼。Python xml minidom。生成<text>部分文字</text>元素
from xml.dom.minidom import Document
doc = Document()
root = doc.createElement('root')
doc.appendChild(root)
main = doc.createElement('Text')
root.appendChild(main)
text = doc.createTextNode('Some text here')
main.appendChild(text)
print doc.toprettyxml(indent='\t')
結果是:
<?xml version="1.0" ?>
<root>
<Text>
Some text here
</Text>
</root>
這是所有罰款和花花公子,但如果我要輸出到這個樣子?
<?xml version="1.0" ?>
<root>
<Text>Some text here</Text>
</root>
這可以輕鬆完成嗎?
Orjanp ...
我也想知道這一點,但我並不滿足於接受的答案,因爲使用它需要安裝pxdom ... – 2010-04-18 13:17:55
隨着xml.dom.minidom的當前版本,即錯誤現在已修復 – usethedeathstar 2014-08-19 06:39:12