Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 07-07-2009, 09:55 PM   #2 (permalink)
pmvinuelas
Registered Member
 
Join Date: Feb 2009
Posts: 87
Question

XMLParser.m
//Parsing the Start of an Element

- (void)parser: (NSXMLParser *)parser didStartElement: (NSString *)elementName
namespaceURI: (NSString *)namespaceURI qualifiedName: (NSString *)qualifiedName
attributes: (NSDictionary *)attributeDict
{
if([elementName isEqualToString: @"Books"])
{
//Initialize the Array
appDelegate.books = [[NSMutableArray alloc] init];
}
else if([elementName isEqualToString: @"Chapters"])
{
//Initialize the Array
appDelegate.chapters = [[NSMutableArray alloc] init];
}

else if([elementName isEqualToString: @"Book"])
{
//Initialize the book
aBook = [[Book alloc] init];

//Extract the attribute here
aBook.bookID = [[attributeDict objectForKey:@"id"] integerValue];

NSLog(@"Reading id value :%i", aBook.bookID);
}
else if([elementName isEqualToString:@"Chapter"])
{
//Initialize the book
aChapter = [[Book alloc] init];

//Extract the attribute here
aChapter.chapter = [[attributeDict objectForKey:@"id"] integerValue];

NSLog(@"Reading id value :%i", aBook.bookID);
}


NSLog(@"Processing Element: %@", elementName);

}
// Parsing an elements value

- (void)parser: (NSXMLParser *)parser foundCharactersNSString *)string
{
if(!currentElementValue)
currentElementValue = [[NSMutableString alloc] initWithString:string];
else
[currentElementValue appendString:string];

NSLog(@"Processing Value: %@", currentElementValue);
}

//Parsing the end of an element

- (void)parser: (NSXMLParser *)parser didEndElement: (NSString *)elementName
namespaceURI: (NSString *)namespaceURI qualifiedName: (NSString *)qName
{
if([elementName isEqualToString:@"Books"])
return;

//There is nothing to do if we encounter books elemnt
//If we encounter the book element however we want to add the book object
//to the array and release the object
else if([elementName isEqualToString:@"Book"])
{
[appDelegate.books addObject:aBook];

[aBook release];
aBook = nil;
}
else
[aBook setValue:currentElementValue forKey:elementName];

[currentElementValue release];
currentElementValue = nil;

}
RootViewController.m (This is for my book titles)

- (void)tableView: (UITableView *)tableView didSelectRowAtIndexPath: (NSIndexPath *)indexPath
{

srvController = [[SecondRootViewController alloc] initWithNibName:@"SecondRootView" bundle:[NSBundle mainBundle]];

//Something here will get you to the second view details!!!
/*
Book *aBook = [appDelegate.books objectAtIndex:indexPath.row];

srvController.aBook = aBook;

*/
//Prepare to tableview.
SecondRootViewController *srvController = [[SecondRootViewController alloc] initWithNibName:@"SecondRootViewController" bundle:[NSBundle mainBundle]];


//Push the new table view on the stack
[self.navigationController pushViewController:srvController animated:YES];

}



SecondRootViewController.m (this is for my chapters)

// Customize the appearance of table view cells.
- (UITableViewCell *)tableViewUITableView *)tableView cellForRowAtIndexPathNSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
pmvinuelas is offline   Reply With Quote
 

» Advertisements
» Stats
Members: 158,731
Threads: 89,189
Posts: 380,525
Top Poster: BrianSlick (7,128)
Welcome to our newest member, goldberg113
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:00 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.