How to Write python to an xml file
This article mainly introduces how to write data to xml files in python. It involves the skills related to the XML module for Python operations on XML files. For more information, see
This example uses the xml module to write xml files.
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
From xml. dom. minidom import Document Doc = Document () People = doc. createElement ("people ") Doc. appendChild (people) Aperson = doc. createElement ("person ") People. appendChild (aperson) Name = doc. createElement ("name ") Aperson. appendChild (name) Personname = doc. createTextNode ("Annie ") Name. appendChild (personname) Filename = "people. xml" F = open (filename, "w ") F. write (doc. toprettyxml (indent = "")) F. close () |
I hope this article will help you with Python programming.
Note <>: For more exciting tutorials, please pay attention to the help house programming