Basically I'm trying to convert all lines in the xml file which contain "Account" in lower case and write it back to file.
My XML looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<TRAINERERADMINSTRATIONOBJECTS>
<TRAINERLIST>
<TRAINER>
<Account>Täst</Account>
<Mark>pUIPBPp8TWw=</Mark>
<Type>lala</Type>
<Business>sghs</Business>
</TRAINER>
</TRAINERLIST>
</TRAINERADMINSTRATIONOBJECTS>
As you can see the source file is in UTF-8! There are "äüö" in the "Account" line.
My Code:
# -*- coding: utf-8 -*-
with open("buht.xml", "r") as s:
for line in s:
if 'Account' in line:
s = open("buht.xml").read().decode('utf-8')
s = s.replace(line, line.decode('utf-8').lower())
f = open("buht.xml", 'w')
f.write(s)
f.close()
With this error:
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe4'
I tried to decode (and desperately encode) it anywhere in the script, but it doesn't work.