Tried & instead of plain & ?
Pure guessing – the parser might interpret that &-character as an HTTP-get-delimiter, hence you might want to specify & instead for a test.
--
You received this message because you are subscribed to the Google Groups "iPhone SDK Development" group.
To post to this group, send email to iphonesdkd...@googlegroups.com.
To unsubscribe from this group, send email to iphonesdkdevelop...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/iphonesdkdevelopment?hl=en.
--
-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *) namespaceURI qualifiedName:(NSString *)qName
attributes: (NSDictionary *)attributeDict
{
NSLog(elementName);
if( [elementName isEqualToString:@"Result"])
{
if(!soapArrayResults)
{
soapArrayResults = [[NSMutableArray alloc] init];
}
xmlArrayResults = YES;
}
}
-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
if (xmlArrayResults) {
NSLog(string);
[soapArrayResults addObject:string];
}
}
If you really get those french characters from the web-server-feed, then it is pretty clear, they are not providing you with wellformed xml in the first place. Well, then again, it might be a customer/partner that you have no handle on, hence you will have to preparse that result you get from the server and make wellformed XML out of it before feeding it to an XML parser. That means, replace any special characters with proper XML-representations.
It will be a bunch of characters that you need to replace, looking something like the code below (note, this is an ancient C++ method I once did – this is not objectiveC, hence possibly not usable out of the box for you unless you are using objectiveC++ already [.mm]).
It builds a straight std::map (hashmap) for the characters to replace and the replacements. This could e.g. be adapted to be done through an NSDictionary and possibly needs more characters to cover – however, you may get the idea…
#include <map>
/*\
* <---------- sXmlTidy ---------->
* @m translation function for XML-conformant strings
* --> I N <-- @p
* const TCHAR *pszIn - non-xml conformant string
* <-- OUT --> @r
* tstring - xml-conformant string
\*/
tstring CMobileProperty::sXmlTidy(const TCHAR *pszIn)
{
tstring sOut;
map<TCHAR,tstring> mapChar;
map<TCHAR,tstring>::const_iterator iter;
for (char c=' ';c <= '~';c++)
mapChar[c]=c;
mapChar['&']=_T("&");
mapChar['€']=_T("€");
mapChar['£']=_T("£");
mapChar['¿']=_T("¿");
mapChar['¡']=_T("¡");
mapChar['<']=_T("<");
mapChar['>']=_T(">");
mapChar['\"']=_T(""");
mapChar['à']=_T("à");
mapChar['À']=_T("À");
mapChar['á']=_T("á");
mapChar['Á']=_T("Á");
mapChar['ä']=_T("ä");
mapChar['Ä']=_T("Ä");
mapChar['ó']=_T("ó");
mapChar['Ó']=_T("Ó");
mapChar['ö']=_T("ö");
mapChar['Ö']=_T("Ö");
mapChar['©']=_T("©");
mapChar['è']=_T("è");
mapChar['È']=_T("È");
mapChar['é']=_T("é");
mapChar['É']=_T("É");
mapChar['ü']=_T("ü");
mapChar['Ü']=_T("Ü");
mapChar['í']=_T("í");
mapChar['Í']=_T("Í");
mapChar['ñ']=_T("ñ");
mapChar['Ñ']=_T("Ñ");
for (int i=0;i < (int)strlen(pszIn);i++)
{
//do not replace characters that seem wellformed already…
if (pszIn[i] == '&' && pszIn[i+1] == '#')
sOut+=pszIn[i];
else
{ //we found a non wellformed character, replace it….
iter=mapChar.find((TCHAR)pszIn[i]);
if (iter != mapChar.end())
sOut+=iter->second;
else
{
TRACEIT2("illegal character code 0x%02X",pszIn[i]);
}
}
}
return sOut;
-(NSString*)ConvertSpecialChar:(NSString *)stringToConvert
{
NSLog(@"%@",webData);
NSInteger i;
NSArray *clefs = [NSArray arrayWithObjects:@"&",@"é",@"ô", nil];
NSArray *values = [NSArray arrayWithObjects:@"&", @"é",@"ô", nil];
NSDictionary *dict=[NSDictionary dictionaryWithObjects:values forKeys:clefs];
NSArray *keys = [dict allKeys];
for (i=0; i<[keys count]; i++) {
NSString *searchForMe = [keys objectAtIndex:i];
NSRange range = [stringToConvert rangeOfString : searchForMe];
if (range.location != NSNotFound) {
stringToConvert= [stringToConvert stringByReplacingOccurrencesOfString:searchForMe withString:[dict objectForKey:searchForMe]];
}
}
return stringToConvert;
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
[connection release];
NSLog(@"Data has been loaded");
NSLog(@"DONE. Received Bytes: %d", [webData length]);
NSLog(@"%@",webData);
NSString *responseString = [[NSString alloc] initWithData:webData encoding:NSUTF8StringEncoding];
if( xmlParser )
{
[xmlParser release];
}
NSString *conversion=[self ConvertSpecialChar:responseString];
NSLog(@"After conversion%@",conversion);
webData = [conversion dataUsingEncoding: NSASCIIStringEncoding];
NSLog(@"After conversion%@",webData);
xmlParser = [[NSXMLParser alloc] initWithData: webData];
[xmlParser setDelegate: self];
[xmlParser setShouldResolveExternalEntities: YES];
[xmlParser parse];
NSLog(responseString);
[responseString release];
[webData release];
}
After conversion<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body><GetListServicesResponse xmlns="http://tempuri.org/"><GetListServicesResult xmlns:a="http://schemas.datacontract.org/2004/07/DtoModelLayer" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><a:ServiceDto><a:ReadOk>APR&D</a:ReadOk><a:ServiceId>1</a:ServiceId><a:ServiceName>Pôle Etudes Dév</a:ServiceName><a:WriteOk>AR&Users</a:WriteOk></a:ServiceDto></GetListServicesResult></GetListServicesResponse></s:Body></s:Envelope>
2010-12-22 10:41:32.113 IphonePlanning[2081:207] s:Envelope
2010-12-22 10:41:32.113 IphonePlanning[2081:207] s:Body
2010-12-22 10:41:32.113 IphonePlanning[2081:207] GetListServicesResponse
2010-12-22 10:41:32.113 IphonePlanning[2081:207] GetListServicesResult
2010-12-22 10:41:32.114 IphonePlanning[2081:207] a:ServiceDto
2010-12-22 10:41:32.114 IphonePlanning[2081:207] a:ReadOk
2010-12-22 10:41:32.114 IphonePlanning[2081:207] APR
2010-12-22 10:41:32.114 IphonePlanning[2081:207] &
2010-12-22 10:41:32.114 IphonePlanning[2081:207] D
2010-12-22 10:41:32.114 IphonePlanning[2081:207] a:ServiceId
2010-12-22 10:41:32.114 IphonePlanning[2081:207] 1
2010-12-22 10:41:32.115 IphonePlanning[2081:207] a:ServiceName
2010-12-22 10:41:32.115 IphonePlanning[2081:207] P
2010-12-22 10:41:32.115 IphonePlanning[2081:207] ô
2010-12-22 10:41:32.115 IphonePlanning[2081:207] le Etudes
2010-12-22 10:41:32.115 IphonePlanning[2081:207] &
2010-12-22 10:41:32.115 IphonePlanning[2081:207] D
2010-12-22 10:41:32.115 IphonePlanning[2081:207] é
2010-12-22 10:41:32.115 IphonePlanning[2081:207] v
2010-12-22 10:41:32.116 IphonePlanning[2081:207] a:WriteOk
2010-12-22 10:41:32.116 IphonePlanning[2081:207] AR
2010-12-22 10:41:32.116 IphonePlanning[2081:207] &
2010-12-22 10:41:32.116 IphonePlanning[2081:207] Users