2009-09-11 1 views
3

다음 코드 - xml 파일을 읽는 방법이 있습니다. 그러나 그것은 나를 위해 매우 느리게 작동합니다. & 데이터를 더 빨리 읽어 들일 수있는 충분한 방법이 없습니까?iPhone에서 더 빠른 xml 읽기가 필요합니다.

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; 
} 

}

나를 다시 내 질문을 명확히하자.

나는 xml을 읽는 이런 방식으로는 충분하지 않다는 것을 관찰했다. 이 방법을 사용하면 iPhone이 데이터를 매우 느리게로드합니다. 왜냐하면, 아이폰은 & 때마다 각 태그를 비교 읽습니다.

더 빠른 XML로드가 필요합니다. & 구문 분석. adc에서 나와 함께

답변

3

XMLPerformance이라고하는 Apple의 사례에는 성능 측면에서 libxml과 NSXMLParser가 나와 있습니다. libxml의 구현을 확인하십시오.

2

SiesmicXML 및 TopSongs 코드 샘플을 지식을 공유하기위한 사전에

덕분에 사용자 대기 시간의 최소의 원인이 XML을 구문 분석의 몇 가지 방법을 보여줍니다.

+0

@ennuikiller - 선생님,이 코드 샘플을 어디에서 구할 수 있습니까? –

+1

http://developer.apple.com/iphone/library/samplecode/SeismicXML/index.html – ennuikiller

2

libxml C 라이브러리 또는 TouchXML 래퍼를 보았습니까? 또한 감속을 유발하는 NSXMLParser라고 확신합니까? Instruments 또는 Shark를 사용하여 애플리케이션을 프로파일 링하고 핫스팟을 찾는 빠른 실행을 원할 수 있습니다.