I am getting a path separator error in python 2.6.1. I have not found this issue with python 2.7.2 version, but unfortunately I need this in 2.6.1 only. Is there any another way
You are using an XPath expression, that is not supported by the ElementTree
version included in Python 2.6. You'll need to filter for the attribute manually, after a .findall()
:
def final_xml(self,username):
users = self.root.findall("user")
for user in users:
if user.attrib.get('username') == 'user1':
break
else:
raise ValueError('No such user')
# `user` is now set to the correct element
self.root.remove(user)
print user
tree = ET.ElementTree(self.root)
tree.write("msl.xml")