def writeToFile (self, rfid, nameofchip, numberofchip) : doc = ElementTree(file = self.__filename); root = doc.getroot() for chips in root.getchildren(): chipid = int((chips.find('chip-id')).text) if chipid == rfid : #if id is already in the xml, delete the tuple root.remove(chips) #create the new Element for the ElementTree chip = xmltree.Element('chips') chip_id = xmltree.Element('chip-id') chip_id.text = ElementTree.__str__(rfid) name = xmltree.Element('name') name.text = nameofchip numbers = xmltree.Element('numbers') numbers.text = ElementTree.__str__(numberofchip) chip.insert(0, chip_id) chip.insert(1, name) chip.insert(2, numbers) # and append it to the existing tree root.append(chip) xmltree.ElementTree(root).write(self.__filename)