Jurudocs
Jurudocs

Reputation: 9175

Replacement of an ampersand in xml document after encodings/decodings

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?

Upvotes: 6

Views: 3917

Answers (2)

chown
chown

Reputation: 52778

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')

Upvotes: 3

Andrey Sboev
Andrey Sboev

Reputation: 7682

may be change

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

to

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

Upvotes: 3

Related Questions