How to include "&" in XML file

202 Views Asked by At

I need the following output in an XML

log="+ Passed Open the Website
"

Here is the relevant part of the code

var1 = '
'
var2 = f' + {res} {na}{var1}'
var2 = var2.replace('&', '&')
case = ET.SubElement(
    suite,
    "testcase",
    {
        "name": f"{na}",
        "log": f'{var2}'

I have tried .replace and escape but every time it shows this output.

log=" + Passed Load Home Page
"

How can I replace the &amp with &?

2

There are 2 best solutions below

3
On BEST ANSWER

If your output is 
 then it means that you are re-escaping.
Try to unescape before outputing it, e.g.:

var1 = unescape('
')
1
On

With this:

text = text.replace("&", "&")