1

I'm loading an XML file containing about 600 small data sets, which is about 10,000 lines. The data is being used as annotation points on a map. I'm using the TouchXML library to handle the XML. Here is my code:

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

After the XML file has downloaded, it crashes with this error:

James Skidmore
  • 49,340
  • 32
  • 108
  • 136
  • 1
    What is the actual exception that is thrown? Let it fully crash past the breakpoint. It should say something `object does respond to selector` or something. – Alex Wayne Mar 13 '11 at 20:40
  • This line looks like it's left over from a previous implementation of iterating over nodes: CXMLElement *node = [nodes objectAtIndex:i]; – kennbrodhagen Mar 13 '11 at 20:47
  • Squeegy, I didn't set any breakpoints, so I guess TouchXML had breakpoints included? How do I get rid of them? – James Skidmore Mar 13 '11 at 20:56
  • There's a chance your NSMutableString is being autoreleased before you get to your enumeration loop. Try and autorelease the returned value instead i.e. `return [theStringValue autorelease]` – Rog Mar 13 '11 at 21:56

1 Answers1

2

From the screenshot I can see that there's a mutateError occuring. This can happen during a fast enumeration if you modify the thing you are enumerating over. Is anything going on that would modify the [self children] collection at the same time as your fast enumeration is running? Are there multiple threads doing things, for example?

If you continue the debugger and allow the exception to be fully thrown, what do you see on the console?

Btw, your .php script appears to be returning a non-valid XML document -- some of the chars are not valid UTF8, as far as my browser is concerned. Maybe not the problem, but worth fixing and ruling out.

occulus
  • 16,959
  • 6
  • 53
  • 76