The example in this article describes how Python creates XML. Share to everyone for your reference. The implementation method is as follows:
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 ()
Hopefully this article will help you with Python programming.