1

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;/>

MH175
  • 2,234
  • 1
  • 19
  • 35
  • 2
    The single quote is an invalid character in an XML attribute, and is escaped as "XML character reference" `'` , see for example http://stackoverflow.com/a/730150/1187415. – Martin R Dec 26 '16 at 20:36

1 Answers1

0

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!

MH175
  • 2,234
  • 1
  • 19
  • 35