I’m trying to parse XML with characters like é, ñ I’m using UTF8 as encoding..
I have already tried change the encode to NSISOLatin1StringEncoding but It doesn’t work
The code is:
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
//NSLog(@"DONE. Received Bytes: %d", [webData length]);
NSString *theXML = [[NSString alloc] initWithBytes: [webData mutableBytes] length:[webData length] encoding:NSUTF8StringEncoding];
// NSLog(theXML);
[theXML release];
if( xmlParser )
{
[xmlParser release];
}
xmlParser = [[NSXMLParser alloc] initWithData: webData];
[xmlParser setDelegate:self];
[xmlParser setShouldResolveExternalEntities:YES];
[xmlParser parse];
if (connection) {
[connection release];
}
}
-(void)callWS {
NSString *url = @"theUrlHere";
NSMutableURLRequest *request =[[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:url]];
[request setHTTPMethod:@"GET"];
NSURLConnection *conn=[[NSURLConnection alloc] initWithRequest:request delegate:self];
if (conn) {
webData = [[NSMutableData data] retain];
}
When I receive the xml response…The results with special characters appears wrong…
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if(!soapResults)
{
....//the soapResults here appears wrong when It has special chars...
}
Example: Caperuçú appears çú , Indianópolis appears ópolis
See the documentation of the
parser:foundCharacters:delegate method:I assume that your code does not accumulate the characters and just uses the result of the last
parser:foundCharacters:call.The following sample program shows this effect with your input strings:
Output:
So this is not an encoding issue.