Domanda

Ho il seguente codice: metodi per leggere i file XML. Ma funziona molto lentamente per me. Non esiste un modo sufficiente per recuperare & amp; leggere i dati più velocemente.

if(connectionRemaining)
{
    [self LoadingPopUp];
    NSURL *tmpURl=[NSURL URLWithString:[NSString stringWithFormat:@"%@getcategory.php",[iGolfAppDelegate getServerPath]]];
    NSMutableURLRequest *theRequest=[NSMutableURLRequest requestWithURL:tmpURl];
    NSURLConnection *conn=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
    if(conn)
        myWebData=[[NSMutableData data] retain];
    connectionRemaining=NO;
}

-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
[myWebData setLength: 0];
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
[myWebData appendData:data];
}
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
[connection release];
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection {
//  NSString *theXML = [[NSString alloc] initWithBytes: [myWebData mutableBytes] length:[myWebData length] encoding:NSUTF8StringEncoding];
//  NSLog(@"%@",theXML);[theXML release];   
if( myXMLParser )
    [myXMLParser release];
myXMLParser = [[NSXMLParser alloc] initWithData: myWebData];
[myXMLParser setDelegate: self]; [myXMLParser setShouldResolveExternalEntities: YES];
[myXMLParser parse];[connection release];[myWebData release];
}

#pragma mark
#pragma mark XMLParsing Methods
-(void)parser:(NSXMLParser*)parser didStartElement:(NSString*)elementName namespaceURI:(NSString*)namespaceURI qualifiedName:(NSString*)qualifiedName attributes:(NSDictionary*)attributeDict {
if([elementName isEqualToString:@"category"])
    categoryArray=[[NSMutableArray alloc]init];
else if([elementName isEqualToString:@"Prop_Category"])
    aCategory=[[Category alloc] init];
}

-(void)parser:(NSXMLParser*)parser foundCharacters:(NSString*)string {
if(!currentElementValue)
    currentElementValue=[[NSMutableString alloc] initWithString:string];
else
    [currentElementValue appendString:string];
}
-(void)parser:(NSXMLParser*)parser didEndElement:(NSString*)elementName namespaceURI:(NSString*)namespaceURI qualifiedName:(NSString*)qualifiedName {
if([elementName isEqualToString:@"category"])
{ [LoadingAlert dismissWithClickedButtonIndex:0 animated:YES]; [LoadingAlert release];[self categoryPickerDiplay]; return;  }
else if([elementName isEqualToString:@"Prop_Category"])
{ [categoryArray addObject:aCategory];[aCategory release];aCategory=nil; }
else{   
    [aCategory setValue:currentElementValue forKey:elementName];
    [currentElementValue release];currentElementValue=nil;
}

}

Vorrei chiarire di nuovo la mia domanda.

Ho osservato che questo modo di leggere xml non è sufficiente. In questo modo iPhone carica i dati molto lentamente. Perché, iPhone leggerà & amp; confronta ogni tag ogni volta.

Voglio un caricamento XML più veloce & amp; Parsing.

Grazie in anticipo per aver condiviso le tue conoscenze con me

È stato utile?

Soluzione

C'è un esempio di Apple chiamato XMLPerformance che illustra libxml vs. NSXMLParser in termini di prestazioni. Controlla la sua implementazione di libxml.

Altri suggerimenti

Gli esempi di codice SiesmicXML e TopSongs da adc mostrano alcuni modi di analisi di XML che causano un minimo di tempo di attesa dell'utente.

Hai guardato libxml C o la TouchXML per questo? Inoltre, sei sicuro che sia il NSXMLParser a causare il tuo rallentamento? Potresti voler fare una rapida panoramica usando Instruments o Shark per profilare l'applicazione e trovare gli hotspot.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top