我已經使這種方法從URL下載XML。 問題是編碼字符。XML下載NSUTF8String編碼問題
-(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];
}
我看不到的特殊卡拉科特像'或重點ù - A - ò等....
這是Web服務http://demo.gigamips.com/rss.php?authkey=12345
是否存在用於檢查此URL是否爲XML的網站UTF- 8實時? – WalterFantauzzi 2012-07-17 08:02:18