Python创建xml的方法_python教程-查字典教程网
Python创建xml的方法
Python创建xml的方法
发布时间:2016-12-28 来源:查字典编辑
摘要:本文实例讲述了Python创建xml的方法。分享给大家供大家参考。具体实现方法如下:fromxml.dom.minidomimportDoc...

本文实例讲述了Python创建xml的方法。分享给大家供大家参考。具体实现方法如下:

from xml.dom.minidom import Document class write_xml(Document): def __init__(self): Document.__init__(self) def set_tag(self,tag): self.tag = tag self.tag1 = self.createElement(self.tag) self.appendChild(self.tag1) self.maincard = self.createElement("card") self.maincard.setAttribute("id", "main") self.maincard.setAttribute("id2","main2") self.tag1.appendChild(self.maincard) self.paragraph1 = self.createElement("p") self.maincard.appendChild(self.paragraph1) self.ptext = self.createTextNode("This is a test!") self.paragraph1.appendChild(self.ptext) def display(self): print self.toprettyxml(indent=" ") wx = write_xml() wx.set_tag('test') wx.display()

希望本文所述对大家的Python程序设计有所帮助。

相关阅读
推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
  • 大家都在看
  • 小编推荐
  • 猜你喜欢
  • 最新python学习
    热门python学习
    脚本专栏子分类