connect XML file to Label (objective-C)

anhbeu

New Member
I have an \[code\]UIViewController\[/code\] page with one button and one label . I added xml parser on my project and everything works (I test it in console), right now I want to connect my XML file to my label to just get one attribute of XML file(for test). My question is how can I connect XML to my label. Would you please give me some hint for implementing this?I'm new to objective-CHere is my code:I just want to see how we can connect xml file to label\[code\] - (void)viewDidLoad { //appDelegate = (testAppDelegate *)[[UIApplication sharedApplication] delegate]; label.textColor = [UIColor greenColor]; // label.text = aBook.title; //it not working, I don't know what should I write to get one // element of xml file to this label or first element of xml file [super viewDidLoad]; }\[/code\]Here is my xml file\[code\]<?xml version="1.0" encoding="UTF-8"?><Books><Book id="1"> <title> Circumference</title> <author>Nicholas Nicastro</author> <summary>Eratosthenes and the Ancient Quest to Measure the Globe.</summary></Book><Book id="2"> <title>Copernicus Secret</title> <author>Jack Repcheck</author> <summary>How the scientific revolution began</summary></Book><Book id="3"> <title>Angels and Demons</title> <author>Dan Brown</author> <summary>Robert Langdon is summoned to a Swiss research facility to analyze a cryptic symbol seared into the chest of a murdered physicist.</summary></Book><Book id="4"> <title>Keep the Aspidistra Flying</title> <author>George Orwell</author> <summary>A poignant and ultimately hopeful look at class and society, Keep the Aspidistra Flying pays tribute to the stubborn virtues of ordinary people who keep the aspidistra flying. </summary></Book>\[/code\]and if it's needed here is my parser class:\[code\]- (Presentation1NameXML *) initXMLParser {appDelegate = (testAppDelegate *)[[UIApplication sharedApplication] delegate];return self;}- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementNamenamespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedNameattributes:(NSDictionary *)attributeDict {if([elementName isEqualToString:@"Books"]) { //Initialize the array. appDelegate.books = [[NSMutableArray alloc] init];}else if([elementName isEqualToString:@"Book"]) { //Initialize the book. aBook = [[Presentation1Name alloc] init]; //Extract the attribute here. aBook.bookID = [[attributeDict objectForKey:@"id"] integerValue]; NSLog(@"Reading id value :%i", aBook.bookID);}NSLog(@"Processing Element: %@", elementName); }- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {if(!currentElementValue) currentElementValue = http://stackoverflow.com/questions/12815308/[[NSMutableString alloc] initWithString:string]; else [currentElementValue appendString:string];NSLog(@"Processing Value: %@", currentElementValue);} - (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 the Books element here.//If we encounter the Book element howevere, we want to add the book object to the array// and release the object.if([elementName isEqualToString:@"Book"]) { [appDelegate.books addObject:aBook]; aBook = nil;}else [aBook setValue:currentElementValue forKey:elementName];currentElementValue = http://stackoverflow.com/questions/12815308/nil;}@end\[/code\]Edit: when I used \[code\] NSLog(@"%@", aBook.title); I got NULL\[/code\]Editin some sample that I saw they have something like this also\[code\] Book *aBook = [appDelegate.books objectAtIndex:indexPath.row]; \[/code\]since they use it in tableView But I don't have any table what should I write instead of objectAtIndex:indexPath.row];
 
Back
Top