2009-09-11 3 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のデータ読み込みが非常に遅くなります。なぜなら、iphoneは毎回各タグを&と比較するからです。

XML読み込みを高速化したい&構文解析。 adcから私と一緒に

答えて

3

XMLPerformanceというAppleの例では、パフォーマンスに関してlibxmlとNSXMLParserを示しています。 libxmlの実装を確認してください。

2

SiesmicXMLとTopSongsコードサンプルをあなたの知識を共有するため、事前に

おかげで、ユーザーの待ち時間の最小値を引き起こすXMLを解析するいくつかの方法を示しています。

+0

@ennuikiller - sir、このコードサンプルはどこで入手できますか? –

+1

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

2

libxml Cライブラリ、またはTouchXMLラッパーを見ましたか?また、あなたの減速の原因となっているのはNSXMLパーサーだと確信していますか?インスツルメントまたはシャークを使用してアプリケーションをプロファイリングしてホットスポットを見つけるために、迅速な実行が必要な場合があります。

関連する問題