0

I'm using an ASP request returning a XML file containing some latin characters. By using this code :

NSData *data = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://www.my-link.asp"]];
NSString *str = [[NSString alloc] initWithData:data encoding:NSISOLatin1StringEncoding];

I read almost every char of the file correctly. Almost, because some of them are replaced by this char : ¿. I'm talking about the bullet (•, 8226) and the right single quotation mark (’, 8217), but I bet I'm going to have some issues with other unusual chars.

My XML prefix is <?xml version="1.0" encoding="ISO-8859-1"?>. I wonder if there is a problem with my XML file or with my code, and how to solve it.

Rob
  • 15,732
  • 22
  • 69
  • 107
  • Are you sure the response is actually in 'ISO-8859-1', and that it's not just the xml-declaration stating that it is? – fguchelaar Feb 19 '13 at 12:19
  • 3
    If the file really is in `ISO-8859-1`, it can't contain the bullet or right single quotation mark unless they are quoted `•` and `’`, because they don't exist in `ISO-8859-1`. However i think they exist in Microsoft's variant `Windows-1252`. Most likely the code generating the XML is not using a proper method for serializing the XML, or its conflating `ISO-8859-1` and `Windows-1252`. It's probably just concatenating strings or some such, which is a huge no-no. See http://stackoverflow.com/questions/3034611/whats-so-bad-about-building-xml-with-string-concatenation – Christoffer Hammarström Feb 19 '13 at 12:23
  • I just tried to save the XML result file with TextWrangler and Latin 1 encoding, and I got these errors repeatedly for every char : `untitled text:1: The character “’” (unicode 0x2019) cannot be represented in the “Western (ISO Latin 1)” encoding` – Rob Feb 19 '13 at 12:33
  • 2
    So use UTF-8 instead. And make sure you use a proper method of generating XML. `""+escape(value)+""` just doesn't cut it. – Christoffer Hammarström Feb 19 '13 at 12:35

1 Answers1

0

Using UTF-8 instead of ISO-8859-1 solved it.

Rob
  • 15,732
  • 22
  • 69
  • 107