gpt4 book ai didi

iphone - iPhone 需要更快的 XML 读取速度

转载 作者:行者123 更新时间:2023-12-03 19:35:43 27 4
gpt4 key购买 nike

我有以下代码 - 读取 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 加载和解析。

最佳答案

Apple 有一个名为 XMLPerformance 的示例这说明了 libxml 与 NSXMLParser 在性能方面的比较。查看其 libxml 的实现。

关于iphone - iPhone 需要更快的 XML 读取速度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1412281/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com