0

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

logi-kal
  • 7,107
  • 6
  • 31
  • 43
Abhishek Rai
  • 2,159
  • 3
  • 18
  • 38

2 Answers2

1

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

var1 = unescape('
')
logi-kal
  • 7,107
  • 6
  • 31
  • 43
  • 1
    What do you mean by "missing"? ` ` represents just a newline. – logi-kal Aug 25 '21 at 10:57
  • 1
    Nope, see [What characters do I need to escape in XML documents?](https://stackoverflow.com/questions/1091945) – logi-kal Aug 25 '21 at 11:02
  • 1
    In any case, it seems that your library is taking care of escaping for you, so you should not care of the syntax of your output. – logi-kal Aug 25 '21 at 11:05
0

With this:

text = text.replace("&", "&")
aldegalan
  • 480
  • 2
  • 12