import xml.etree.ElementTree as ET
var3 = raw_input("Enter the root Element: \n")
root = ET.Element(var3)
var4 = raw_input("Enter the sub root Element: \n")
doc = ET.SubElement(root, var4)
no_of_rows=input("Enter the number of Element for XML files: - \n")
def printme():
var = raw_input("Enter Element: - \n")
var1 = raw_input("Enter Data: - \n")
ET.SubElement(doc, var).text =var1
return;
for num in range(0, no_of_rows):
printme()
tree = ET.ElementTree(root)
file = raw_input("Enter File Name: - \n")
tree.write(file)
ET.ElementTree(root).write(file, encoding="utf-8", xml_declaration=True)
print "Xml file Created..!!"
I want to create xml dynamically using python.
How to create multiple sub roots?
I am giving file name from the console to store written elements in xml. It is giving this error:
TypeError: descriptor 'write' requires a 'file' object but received a 'str'
What should I do?