Download our e-book of Introduction To Python
Neha Kumawat
4 years ago
<?xml version = "1.0"
encoding = "iso-8859-1"?>
<studentlist>
<student>
<name>Amit</name>
<subject>Physics</subject>
<marks>80</marks>
</student>
<student>
<name>Karan</name>
<subject>Maths</subject>
<marks>100</marks>
</student>
<student>
<name>Sahil</name>
<subject>Biology</subject>
<marks>98</marks>
</student>
</studentlist>
student=xmlobj.Element('student')
a = xmlobj.SubElement(student, 'name')
a.text='name'
subject = xmlobj.SubElement(student, 'subject')
a.text='Amit'
subject.text='Physics'
marks = xmlobj.SubElement(student,'marks')
marks.text='80'
tree = xmlobj.ElementTree(root)
file = open('studentlist.xml','wb')
tree.write(file)
file.close()
for child in children:
student={}
pairs = child.getchildren()
for pair in pairs:
product[pair.tag]=pair.text