У меня есть XML-файл
<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
<PageDescription>
<Page>
<Row />
<Row>
<Cell cellRow="0" cellColumn="0" Pos="693" />
<Cell cellRow="0" cellColumn="1" Pos="2693" />
</Row>
</Page>
</PageDescription>
, который содержит различные структуры и атрибуты.Теперь я хочу изменить значение, например, атрибута Pos, добавив определенное смещение, в данном случае 12. Но я получил ошибку.
for currfile in allfiles:
filepathstr = xmldir + "/" + currfile;
tree = xee.ElementTree(file=filepathstr)
for tag in tree.findall('Page'):
for tag2 in tag.findall('Row'):
for tag3 in tag2.findall('Cell'):
selectTag = tag3.attrib['Pos']
newVal = int(selectTag)+12
tag3.set('Pos', newVal)
expfilename = expdir + "/" + currfile
tree.write(expfilename,encoding="ISO-8859-1")
Я получаю следующую ошибку
<class 'xml.etree.ElementTree.ElementTree'>
---------------------------------------------------------------------------
TypeError
Traceback (most recent call last)
C:\ProgramData\Anaconda3\lib\xml\etree\ElementTree.py in _escape_attrib(text)
1079 try:
-> 1080 if "&" in text:
1081 text = text.replace("&", "&")
TypeError: argument of type 'int' is not iterable
During handling of the above exception, another exception occurred:
TypeError Traceback (most recent call last)
<ipython-input-2-b1ffea99d1f3> in <module>()
67 expfilename = expdir + "/" + currfile
68
---> 69 tree.write(expfilename,encoding="ISO-8859-1")
Кто-нибудь видит ошибку?Или такие задачи проще с XPath?