Pythonの中でDOMでXMLサンプルを作成

仕様:
xml.dom.minidom
輸出:
b’\n\n\tHelloWorld\n\n’
ファイルを出力すれば、ファイルはバイナリで開く必要がある。

サンプルコード:
dom_xml.py

import xml.dom.minidom
doc = xml.dom.minidom.Document()
resource = doc.createElement('resources’)
doc.appendChild(resource)
string = doc.createElement('string’)
string.setAttribute('name’, 'こんにちは’)
value = doc.createTextNode('こんにちは’)
string.appendChild(value)
resource.appendChild(string)
print(doc.toprettyxml(encoding=’utf-8′))

Source

Posted by arkgame