I've used some methods from this tutorial:
Parsing XML Files - iPhone SDK Articles
It's a xml listed with boats and the method looks like this:
I don't use any array to return.
Code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
Boat *newBoat = [appDelegate.boats objectAtIndex:indexPath.row];
cell.text = newBoat.model;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
// Set up the cell
return cell;
}
This if a function in AppDelegate.m
Code:
- (void)applicationDidFinishLaunching:(UIApplication *)application {
NSString *xmlStart = @"http://www.mysite.com/search=";
NSString *searchWord = passedString;
NSString *xmlEnd = @"&xml=1";
NSString *newString;
newString = [xmlStart stringByAppendingString:searchWord];
XML = [newString stringByAppendingString:xmlEnd];
NSURL *url = [[NSURL alloc] initWithString:XML];
NSXMLParser *boatListParser = [[NSXMLParser alloc] initWithContentsOfURL:url];
BoatListParser *parser = [[BoatListParser alloc] initBoatListParser];
[boatListParser setDelegate:parser];
BOOL success = [boatListParser parse];
if(success)
NSLog(@"Success");
else
NSLog(@"Error");
// Configure and show the window
[window addSubview:[navigationController view]];
[window makeKeyAndVisible];
}