How To Find, Read And Replace A Value In Xml File With Python
This is my example XML file: Hide your heartBonnie Tyler)
[<Element 'CD' at 0x7fc0a22c1778>]
e.findall('DATA')
[]
Wrong level of chacking ...
Solution 2:
I found the solution, I only had to first read the value, turn it in an integer, add 1 and replace the value turning it again into a string:
import xml.etree.ElementTree as ET
tree = ET.parse('test.xml')
root = tree.getroot()
newTimes = int(root[0][7].text) + 1
root[1][6].text = str(newTimes)
tree.write('test.xml')
That's all.
Post a Comment for "How To Find, Read And Replace A Value In Xml File With Python"