Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replacement of an ampersand in xml document after encodings/decodings

Tags:

python

replace

How do i replace a amphersand with the html sign & in a xml document? normally it works simply with

a = u"TORE & Co & KG"
i = a.replace('&','&')
print i 

Here it doesn't work:i get my xml structure out of an email and process it like this:

saver=StringIO(u"") # Edit
a=str(msg)
i= a.decode('quopri').decode('utf-8')
saver.write(i)
savercontent = saver.getvalue()
savercontent.replace('&','&') 

In the end the replacement dosen't work...no errors..., how can i fix this? I guess this is connected with the encodings/decodings... Any help?

like image 538
Jurudocs Avatar asked Nov 02 '11 21:11

Jurudocs


2 Answers

You could try:

a = str(msg)
i = a.decode('quopri').decode('utf-8').replace('&', '&')
saver.write(i)
savercontent = saver.getvalue()

Or try:

i = a.decode('quopri').replace('&', '&').decode('utf-8')
like image 160
chown Avatar answered Sep 30 '22 15:09

chown


may be change

savercontent.replace('&','&')

to

savercontent = savercontent.replace('&','&')
like image 31
Andrey Sboev Avatar answered Sep 30 '22 15:09

Andrey Sboev