我正在加载一个XML 文件,其中包含大约 600 个小数据集,大约 10,000 行。数据被用作地图上的注释点。我正在使用该TouchXML
库来处理 XML。这是我的代码:
NSData *XMLData = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://skidmoreapps.com/darksky/fetch_info.php"]];
CXMLDocument *doc = [[[CXMLDocument alloc] initWithData:XMLData options:0 error:nil] autorelease];
NSArray *nodes = [doc nodesForXPath:@"//site" error:nil];
for (CXMLElement *node in nodes)
{
ObservationSite *site = [ObservationSite mapAnnotation];
[site setCoordinate:CLLocationCoordinate2DMake([[[[node elementsForName:@"lat"] objectAtIndex:0] stringValue] floatValue], [[[[node elementsForName:@"lng"] objectAtIndex:0] stringValue] floatValue])];
[site setTitle:[[[node elementsForName:@"name"] objectAtIndex:0] stringValue]];
[site setAddress:[[[node elementsForName:@"address"] objectAtIndex:0] stringValue]];
[site setUrl:[[[node elementsForName:@"name_l"] objectAtIndex:0] stringValue]];
[site setAffiliation:[[[node elementsForName:@"affil"] objectAtIndex:0] stringValue]];
[site setAffiliationUrl:[[[node elementsForName:@"affil_l"] objectAtIndex:0] stringValue]];
[site setOwner:[[[node elementsForName:@"owner"] objectAtIndex:0] stringValue]];
[site setFee:[[[node elementsForName:@"fee"] objectAtIndex:0] stringValue]];
[site setAccess:[[[node elementsForName:@"access"] objectAtIndex:0] stringValue]];
[site setSky:[[[node elementsForName:@"sky"] objectAtIndex:0] stringValue]];
[site setWeatherUrl:[[[node elementsForName:@"wx_l"] objectAtIndex:0] stringValue]];
[site setPads:[[[node elementsForName:@"pads"] objectAtIndex:0] stringValue]];
[site setParking:[[[node elementsForName:@"parking"] objectAtIndex:0] stringValue]];
[site setRestrooms:[[[node elementsForName:@"b_rooms"] objectAtIndex:0] stringValue]];
[site setSleep:[[[node elementsForName:@"sleep"] objectAtIndex:0] stringValue]];
[site setNotes:[[[node elementsForName:@"notes"] objectAtIndex:0] stringValue]];
[map addAnnotation:site];
}
下载 XML 文件后,它会因以下错误而崩溃: