<grandParent>
<parent>
<child>Sam/Astronaut</child>
</parent>
</grandParent>
I want to modify the above XML by adding another child tag inside parent tag. I'm doing something like this..
tree = ET.parse("test.xml")
a=ET.Element('parent')
b=ET.SubElement(a,"child")
b.text="Jay/Doctor"
tree.write("test.xml")
Is this the correct way of modifying the xml file? Any better way? or what else should I be taking care of in the above code?
No comments:
Post a Comment