다음 코드 - 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에서 나와 함께
@ennuikiller - 선생님,이 코드 샘플을 어디에서 구할 수 있습니까? –
http://developer.apple.com/iphone/library/samplecode/SeismicXML/index.html – ennuikiller