Abhishek Rai
Abhishek Rai

Reputation: 2237

How to include "&" in XML file

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 &?

Upvotes: 0

Views: 220

Answers (2)

logi-kal
logi-kal

Reputation: 7880

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

var1 = unescape('
')

Upvotes: 1

aldegalan
aldegalan

Reputation: 502

With this:

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

Upvotes: 0

Related Questions