Python創(chuàng)建xml的方法
更新時間:2015年03月10日 10:32:15 作者:Sephiroth
這篇文章主要介紹了Python創(chuàng)建xml的方法,實例分析了Python操作XML文件的技巧,具有一定參考借鑒價值,需要的朋友可以參考下
本文實例講述了Python創(chuàng)建xml的方法。分享給大家供大家參考。具體實現(xiàn)方法如下:
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
pandas預處理部分地區(qū)數(shù)據(jù)案例
本文主要介紹了pandas預處理部分地區(qū)數(shù)據(jù)案例,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2023-01-01
Python繪制三角函數(shù)圖(sin\cos\tan)并標注特定范圍的例子
今天小編就為大家分享一篇Python繪制三角函數(shù)圖(sin\cos\tan)并標注特定范圍的例子,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-12-12
python的pytest框架之命令行參數(shù)詳解(下)
這篇文章主要介紹了python的pytest框架之命令行參數(shù)詳解,今天將繼續(xù)更新其他一些命令選項的使用,和pytest收集測試用例的規(guī)則,需要的朋友可以參考下2019-06-06

