views:

64

answers:

0

I've been using NSXMLParser on the iPhone to parse out XML files from the web without any problems. I'm now in a situation though where I want to get the contents of three different URLs and then parse them all at once.

I'm doing this by creating three NSMutableData instances, each filled with the contents of one of the three URLs. I'm then appending those into one NSMutableData file and telling NSXMLParser to parse that data.

The problem is that the parser only appears to parse the contents of the first URL, even though I've verified (by checking the size of each appended piece of data) that the data is being combined correctly.

I'm suspicious that NSXMLParser is stopping the parsing on its own when it encounters the second XML file (when it sees this line: < ?xml version="1.0" encoding="UTF-8"?>)

Here is the relevant code (routeLoaderData is an NSMutableData IVAR):

NSMutableData *data1 = [NSMutableData dataWithContentsOfURL:[NSURL URLWithString:[urlsArray objectAtIndex:0]]];
NSMutableData *data2 = [NSMutableData dataWithContentsOfURL:[NSURL URLWithString:[urlsArray objectAtIndex:1]]];
NSMutableData *data3 = [NSMutableData dataWithContentsOfURL:[NSURL URLWithString:[urlsArray objectAtIndex:2]]];

[routeLoaderData appendData:data1];
[routeLoaderData appendData:data2];
[routeLoaderData appendData:data3];

NSLog(@"[RL] data1 Length: %i",data1.length);
NSLog(@"[RL] data2 Length: %i",data2.length);
NSLog(@"[RL] data3 Length: %i",data3.length);
NSLog(@"[RL] routeLoaderData Length: %i",routeLoaderData.length);

NSXMLParser *parser = [[NSXMLParser alloc] initWithData:routeLoaderData]; 

Does anyone have any thoughts on what might be going on? Or is there a better way that I could be going about doing this?

Thanks!