Swift write contents of XML that uses single quote: '

370 views Asked by At

Swift 3

I am trying to write the contents of an XML file to disk but all my single quotes end up looking like &apos and not '. What do I need to do in order to get the single quotes to be written?


In this XML file, strings are always enclosed in single quotes, and arrays are comma separated.

This is the way an array of names must look when written:

<names value="'Fred', 'Wilma', 'George'"/>

And this is what I'm getting

<names value="&apos;Fred&apos;,&apos;Wilma&apos;,&apos;George&apos;/>

1

There are 1 answers

0
MH175 On

Solved

Martin R's reminder was all I needed to figure out a way to deal with the situation.

I just treated the xml as a literal string and used brute force.

let newXML = xmlAsString.replacingOccurrences(of: "&apos;", with: "'")

Thanks!