So I have the following code:
NSURL *baseURL = [NSURL URLWithString:@"http://www.baseurltoanxmlpage.com"];
NSURL *url = [NSURL URLWithString: @"page.php" relativeToURL:baseURL];
NSArray *array = [NSArray arrayWithContentsOfURL:url];
If the XML page is as follows:
<array><dict><key>City</key><string>Montreal</string></dict></array>
The array returns fine. However, if the XML file is as follows:
<array><dict><key>City</key><string>Montréal</string></dict></array>
The array returns null. I guess this has something to do with the special char "é". How would I deal with these characters? The XML page is generated with PHP. utf8_encode() function makes the array return but then I don't know how to deal with the encoded "é" character.
Here's the working solution:
NSString *stringArray = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];
NSArray *array = [stringArray propertyList];
NSLog(stringArray);
NSLog(@"%@", array);
NSLog([[[array objectAtIndex:0] valueForKey:@"City"] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]);
The first log prints out the "é" fine. In the second log, it's encoded and is printed as "\U00e9". In the 3rd log, it's decoded and printed as "é" (which is what I was looking for).