Python创建xml的方法,Python创建xml方法
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程序设计有所帮助。
相关内容
- Python接收Gmail新邮件并发送到gtalk的方法,pythongtalk
- Python获取DLL和EXE文件版本号的方法,
- Linux下使用python调用top命令获得CPU利用率,pythontop
- Python实现去除代码前行号的方法,python去除代码前行
- 使用graphics.py实现2048小游戏,graphics.py2048
- Python使用xlrd读取Excel格式文件的方法,
- Python获取单个程序CPU使用情况趋势图,pythoncpu
- Python生成随机密码,python生成
- Python写的Tkinter程序屏幕居中方法,pythontkinter
- Python将xml和xsl转换为html的方法,pythonxmlxslhtml
评论关闭