Xcode XML - Display Selected Data

biew55

New Member
I am trying to parse students from an xml file and display them in a tableview. Then, when you click on a student listed in the tableview, it will display the students details in a separate view controller. The xml consists of multiple courses, with each course having multiple students. Below is an example of the xml which consists if the courses Graphics and Photography:\[code\]<Course> <Graphics> <Student> Student Info in here </Student> ... </Graphics> <Photo> <Student> Student Info in here </Student> ... </Photo></Course>\[/code\]I am fairly new to Xcode, but i have read some tutorials on using Xcode and parsing data from an xml file. Below is what i have written in my project to retrieve the student data from the xml file:\[code\]-(void) parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{ if([elementName isEqualToString:@"Course"]) { app.listArray = [[NSMutableArray alloc]init]; } else if ([elementName isEqualToString:@"Graphics"]) { app.listArray = [[NSMutableArray alloc]init]; } else if ([elementName isEqualToString:@"gStudent"]) { theList = [[List alloc]init]; theList.studentID = [[attributeDict objectForKey:@"id"]integerValue]; }}-(void) parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{ if(!currentElementValue) { currentElementValue = http://stackoverflow.com/questions/12709329/[[NSMutableString alloc]initWithString:string]; } else { [currentElementValue appendString:string]; }}-(void) parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{ if ([elementName isEqualToString:@"Course"]) { return; } if([elementName isEqualToString:@"Graphics"]) { return; } if ([elementName isEqualToString:@"gStudent"]) { [app.listArray addObject:theList]; theList = nil; } else { [theList setValue:currentElementValue forKey:elementName]; currentElementValue = http://stackoverflow.com/questions/12709329/nil; }}\[/code\]I am able to retrieve the students from the xml and display them with no problems, and i can also select one of the students in the list and display their details in the view controller.My concern is that when i try to retrieve the students who do Graphics, it seems that the program retrieve and displays the students from Graphics and Photography. But I just want to display the students who do Graphics.I am just wondering is there a way that i can display the students from a chosen course, without displaying the students from the other courses?
 
Back
Top