Python创建xml Python创建xml的方法

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

Python创建xml Python创建xml的方法

Sephiroth   2021-03-21 我要评论
想了解Python创建xml的方法的相关内容吗,Sephiroth在本文为您仔细讲解Python创建xml的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点: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程序设计有所帮助。

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们