There is a xml file like below:
<hh>
<aa>
<cc>
<ee>
<Name>John</Name>
</ee>
<cc>
<ee>
<Name>David</Name>
</ee>
</aa>
<bb>
<dd>
<Name>John</Name>
</dd>
<dd>
<Name>David</Name>
</dd>
</bb>
</hh>
I'm trying to modify the name: "John --> Rose", and "David --> Gina"
So I write the code as below:
import xml.etree.ElementTree as ET
import glob
for file in glob.glob("ff/*.xml"):
tree = ET.parse(file)
root = tree.getroot()
a01 = "aa/cc[1]/ee"
a02 = "bb/dd[1]"
b01 = "aa/cc[2]/ee"
b02 = "bb/dd[2]"
apaths = [a01, a02]
bpaths = [b01, b02]
for i in apaths:
aa = root.findall(apaths)
aa.text = "Rose"
tree.write(file)
for i in bpaths:
bb = root.findall(bpaths)
bb.text = "Gina"
tree.write(file)
But it response "TypeError: unhashable type: 'list'". Could someone help me to correct my code? Many thanks.