The examples in this article describe how Python creates XML. Share to everyone for your reference. The implementation methods are as follows:
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 ()
I hope this article will help you with your Python programming.