Python创建xml的方法
更新时间:2015年03月10日 10:32:15 作者:Sephiroth
这篇文章主要介绍了Python创建xml的方法,实例分析了Python操作XML文件的技巧,具有一定参考借鉴价值,需要的朋友可以参考下
本文实例讲述了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程序设计有所帮助。
相关文章
Django rstful登陆认证并检查session是否过期代码实例
这篇文章主要介绍了Django rstful登陆认证并检查session是否过期代码实例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下2019-08-08
Python绘制三角函数图(sin\cos\tan)并标注特定范围的例子
今天小编就为大家分享一篇Python绘制三角函数图(sin\cos\tan)并标注特定范围的例子,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧2019-12-12


最新评论