我已经制作了这种从 URL 下载 XML 的方法。问题是编码字符。
-(void) scaricamentoXML{
/*Save XML IN LOCALE*/
NSString* docsDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
NSLog(@"Doc dir: %@:",docsDir);
//dichiaro il file locale in cui salvare i dati XML
NSString* fileToDownload = @"provaXML.xml";
NSString *hostURLString = @"http://demo.gigamips.com/rss.php?authkey=12345";
NSURL *xmlURL = [NSURL URLWithString:hostURLString];
NSLog(@"xmlURL = %@", xmlURL);
//gestione codifica UTF-8
NSError *error;
NSString *dataString = [[NSString alloc] initWithContentsOfURL:xmlURL encoding:NSASCIIStringEncoding error:&error];
NSLog(@"DataString = %@", dataString);
//NSData *xml = [[NSData alloc]initWithContentsOfURL:xmlURL];
NSData *xml = [dataString dataUsingEncoding:NSUTF8StringEncoding];
//creo una stringa di appoggio in encoding UTF8 - verificare se funziona
NSString *str = [[NSString alloc] initWithData:xml encoding:NSUTF8StringEncoding];
NSLog(@"NSData xml = %@", xml);
//NSString *newStr = [[NSString alloc] initWithData:xml encoding:NSUTF8StringEncoding];
//NSLog(@"newStr = %@", newStr);
NSString *filePath = [docsDir stringByAppendingPathComponent: fileToDownload];
//[xml writeToFile: filePath atomically: NO];
[str writeToFile: filePath atomically: NO];
/*Save XML IN LOCALE*/
/*SALVO LE IMMAGINI MINI IN LOCALE*/
AuthParserImages *parser=[[AuthParserImages alloc]init];
entryArray=[parser startParserLocale:@"provaXML"];
GestioneImages *gi = [[GestioneImages alloc]init];
for(int i =0; i< [entryArray count];i++){
item=[entryArray objectAtIndex:i];
[gi saveImageLocal:item.urlImageLow :item.id];
}
/*SALVO LE IMMAGINI MINI IN LOCALE*/
/*CREA IL FILE GESTIONE NEW*/
gp = [[GestionePlist alloc]init];
[gp savePlist:@"begin"];
/*CREA IL FILE GESTIONE NEW*/
[self controlloXML];
[activityIndicator stopAnimating];
}
我看不到像 ' 或重音 ù - à - ò 等特殊字符。