您好,欢迎访问一九零五行业门户网

Python创建xml的方法

本文实例讲述了python创建xml的方法。分享给大家供大家参考。具体实现方法如下:
from xml.dom.minidom import documentclass 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程序设计有所帮助。
其它类似信息

推荐信息