简体   繁体   中英

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?

may be change

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

to

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM