Escape XML

Hello.


I'm fetching data from Spotifys Web API. Some of the strings in the response have characters which XML does not like. (&)


How do I escape this string in TVJS? I've tried using XMLSerializer and .replace but they do not seem to work in the tvOS environment.


Thanks in advance,

Jeremy Karlsson

Turn out this worked just fine.


function escapeForXML(string) {
  return string
    .replace(/&/g, '&')
    .replace(/</g, '&lt;')
    .replace(/>/g, '&gt;')
    .replace(/"/g, '&quot;');
}


xCode is giving worthless debug information, so it's really heard to know where the error is. In this case, I forgot to escape a string in the template, but the debug info did not tell me that. Sorry for this thread.

Escape XML
 
 
Q