iphone - parse 2 rss feeds in app delegate -



iphone - parse 2 rss feeds in app delegate -

im next tutorial below , working fine if wanted parse 2 rss feeds seems overwrite 1 array instead of saving them in respective arrays,

http://www.iphonesdkarticles.com/2008/12/parsing-xml-files.html

this in delegate:

nsurl *url2 = [[nsurl alloc] initwithstring:@"myrssfeed1"]; nsxmlparser *xmlparser1 = [[nsxmlparser alloc] initwithcontentsofurl:url2]; //initialize delegate. xmlparser1 *parser1 = [[xmlparser1 alloc] initxmlparser]; //set delegate [xmlparser1 setdelegate:parser1]; //start parsing xml file. bool successs = [xmlparser1 parse]; if(successs) nslog(@"no errors"); else nslog(@"error error error!!!"); //vids nsurl *url = [[nsurl alloc] initwithstring:@"myrssfeed2"]; nsxmlparser *xmlparser = [[nsxmlparser alloc] initwithcontentsofurl:url]; //initialize delegate. xmlparser *parser = [[xmlparser alloc] initxmlparser]; //set delegate [xmlparser setdelegate:parser]; //start parsing xml file. bool success = [xmlparser parse]; if(success) nslog(@"no errors"); else nslog(@"error error error!!!");

that parses feed 1, allocates array parses 2 , seems overwrite first insteaf of using sec array defined as

@synthesize pics; @synthesize books;

and saved in xmlparser & xmlparser1

i cant figure out how stop overwriting.

here xmlparsers too:

- (void)parsers:(nsxmlparser *)parsers didstartelement:(nsstring *)elementname namespaceuri:(nsstring *)namespaceuri qualifiedname:(nsstring *)qualifiedname attributes:(nsdictionary *)attributedict { if([elementname isequaltostring:@"books"]) { //initialize array. appdelegate2.pics = [[nsmutablearray alloc] init]; } else if([elementname isequaltostring:@"book"]) { //initialize book. apics = [[bookphoto alloc] init]; //extract attribute here. apics.bookid = [[attributedict objectforkey:@"id"] integervalue]; nslog(@"reading havid value :%i", apics.bookid); } nslog(@"processing element: %@", elementname); } - (void)parsers:(nsxmlparser *)parsers foundcharacters:(nsstring *)string { if(!currentelementvalue) currentelementvalue = [[nsmutablestring alloc] initwithstring:string]; else [currentelementvalue appendstring:string]; nslog(@"processing value: %@", currentelementvalue); } - (void)parsers:(nsxmlparser *)parsers didendelement:(nsstring *)elementname namespaceuri:(nsstring *)namespaceuri qualifiedname:(nsstring *)qname { if([elementname isequaltostring:@"books"]) return; //there nil if encounter books element here. //if encounter book element howevere, want add together book object array // , release object. if([elementname isequaltostring:@"book"]) { [appdelegate2.pics addobject:apics]; [apics release]; apics = nil; } else [apics setvalue:currentelementvalue forkey:elementname]; [currentelementvalue release]; currentelementvalue = nil; }

and xmlparser.m

- (void)parser:(nsxmlparser *)parser didstartelement:(nsstring *)elementname namespaceuri:(nsstring *)namespaceuri qualifiedname:(nsstring *)qualifiedname attributes:(nsdictionary *)attributedict { if([elementname isequaltostring:@"books"]) { //initialize array. appdelegate.books = [[nsmutablearray alloc] init]; } else if([elementname isequaltostring:@"book"]) { //initialize book. abook = [[book alloc] init]; //extract 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 = [[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 nil if encounter books element here. //if encounter book element howevere, want add together book object array // , release object. if([elementname isequaltostring:@"book"]) { [appdelegate.books addobject:abook]; [abook release]; abook = nil; } else [abook setvalue:currentelementvalue forkey:elementname]; [currentelementvalue release]; currentelementvalue = nil; }

any help on brilliant,

thanks in advance

jonn4y

i suggest putting breakpoint @ point array not getting loaded, , seeing if (1) gets called, , (2), whether saving info array @ all.

iphone objective-c rss

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

c# - Can ProtoBuf-Net deserialize to a flat class? -

javascript - Change element in each JQuery tab to dynamically generated colors -