这是我想创建的xml:
<?xml version="1.0" encoding="utf-8"?>
<DOCUMENT content_method="full">
<param key="k1" value="0001"/>
<param key="k2" value="0002"/>
<param key="k3" value="0003"/>
</DOCUMENT>
这是我的代码:
#!/usr/bin/python
# -*- coding: utf-8 -*-
from xml.dom.minidom import Document
doc = Document()
DOCUMENT = doc.createElement('DOCUMENT')
DOCUMENT.setAttribute('content_method',"full")
#DOCUMENT.setAttribute('xsi:noNamespaceSchemaLocation','DOCUMENT.xsd')
doc.appendChild(DOCUMENT)
param= doc.createElement('param')
param.setAttribute('key',"k1")
param.setAttribute('value',"0001")
DOCUMENT.appendChild(param)
f = open('/home/tel.xml','w')
#f.write(doc.toprettyxml(indent = '\t', newl = '\n', encoding = 'utf-8'))
doc.writexml(f,indent = '\t',newl = '\n', addindent = '\t',encoding='utf-8')
f.close()