Python创建xml的方法
作者:Sephiroth 时间:2021-11-25 05:59:44
本文实例讲述了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,创建,xml
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
OpenCV实现图像平滑处理的方法汇总
2023-07-12 14:44:33
![](https://img.aspxhome.com/file/2023/8/102728_0s.jpg)
Firebox 3 后退后按钮 diasabled 状态不恢复的一个解决方案
2008-11-06 12:28:00
基于Python实现西西成语接龙小助手
2023-04-02 22:12:04
![](https://img.aspxhome.com/file/2023/3/90943_0s.jpg)
php入门学习知识点三 PHP上传
2023-11-23 12:10:49
Python函数用法和底层原理分析
2023-09-13 23:42:37
![](https://img.aspxhome.com/file/2023/6/107286_0s.png)
Sublime Text4 配置 Python3 环境、代码提示、编译报错的解决方案
2021-09-24 12:00:03
![](https://img.aspxhome.com/file/2023/4/72074_0s.png)
python实现从本地摄像头和网络摄像头截取图片功能
2022-04-22 22:32:39
Python实现学生管理系统(面向对象版)
2021-11-05 01:20:54
Python实现文件按照日期命名的方法
2022-10-25 19:40:09
如何利用触发器实现两个数据库间的同步
2009-01-06 11:26:00
Python3.10动态修改Windows系统本地IP地址
2021-07-21 01:10:59
![](https://img.aspxhome.com/file/2023/5/92115_0s.png)
纯ASP结合VML生成完美图-饼图
2010-05-11 16:49:00
python requests.get带header
2022-07-28 20:50:40
![](https://img.aspxhome.com/file/2023/1/97091_0s.jpg)
Cpython解释器中的GIL全局解释器锁
2021-08-29 22:06:43
![](https://img.aspxhome.com/file/2023/7/63907_0s.png)
Python实现制度转换(货币,温度,长度)
2022-01-02 00:42:25
浅谈Python 函数式编程
2022-09-03 20:38:07
PDO::errorInfo讲解
2023-06-06 01:51:53
[译]在线广告及其在网页设计中的重要性
2009-02-06 13:36:00
![](https://img.aspxhome.com/file/UploadPic/20092/6/001-22s.jpg)
教程javascript的function(函数)
2007-09-30 13:38:00
![](https://img.aspxhome.com/file/UploadPic/20079/30/200793013468441s.gif)
python实现输入三角形边长自动作图求面积案例
2023-08-12 01:47:49
![](https://img.aspxhome.com/file/2023/7/94177_0s.jpg)