Вы можете сделать следующее (просто взгляните на документацию l xml).
import lxml.etree as ET
file = "file.xml"
# Grab the root (config node)
root = ET.parse(file).getroot()
# Grab all 'property' nodes
properties = root.findall("property")
# Iterate over them
for property in properties:
# Find the property with name 'prop3'
if property.find("name").text == "prop3":
# Update the value to ten
property.find("value").text = "10"
# Write back the modified file
with open(file, "w") as f:
f.write(ET.tostring(root, encoding="unicode"))
Бонус, вы можете изменить последнюю строку на f.write(ET.tostring(root, encoding="unicode", pretty_print=True))
, чтобы получить хороший XML файл с отступом и возвратом.