Modify a XML using ElementTree
问题 <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? 回答1: Your code creates a whole new tree and adds Jay to it. You