#encoding:utf-8
'''
    write xml in dom style 
'''

from xml.dom.minidom import Document

doc = Document() # new a DOM object

words = doc.createElement('words') # new a root element
words.setAttribute('xmlns:xsi',"http://www.w3.org/2001/XMLSchema-instance")#设置命名空间
doc.appendChild(words)

elem = doc.createElement('word')
elem.setAttribute('name','english')
words.appendChild(elem)

# or you could do like the following:
#elem = doc.createElement('word') #words.appendChild(elem) #text = doc.createElement('name') #text_node = doc.createTextNode('english') #text.appendChild(text_node) #elem.appendChild(text) print doc.toxml()

 

相关文章:

  • 2022-02-22
  • 2021-12-26
  • 2021-11-01
  • 2022-01-01
  • 2022-12-23
  • 2022-01-23
  • 2021-12-12
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-28
  • 2021-09-21
  • 2022-12-23
  • 2021-09-17
  • 2022-12-23
相关资源
相似解决方案