How do you create an xml file using a Python script?

I am trying to create an xml file that contains formatted information from a Revit model for input into another program, and need to use a python script to create it. I can create an equivalent txt file by using the following commands:

file = open(“C:\Users\username\Documents\filename.txt”)

file.write(“info to write to file”)


But even after changing the extension to .xml, the file still isn’t recognized as a real xml file. Any thoughts on how properly create an xml file with a python script?