xml - iOS NSXML dictionary not adding to array -
i have instance of nsxml parser parsing xml , storing in array of objects. xml has image urls , titles trying add dictionary, , add dictionary array in data object. dictionary being set won't add array. below xml , code:
xml:
http://www.flashalert.net/rss.html?id=3753
code:
- (void)parser:(nsxmlparser *)parser foundcharacters:(nsstring *)string { nsstring *string1 = [string stringbyreplacingoccurrencesofstring:@"amp;" withstring:@""]; nsstring *string2 = [string1 stringbyreplacingoccurrencesofstring:@""" withstring:@"\""]; currentnodecontent = (nsmutablestring *) [string2 stringbystrippinghtml]; } - (void)parser:(nsxmlparser *)parser didstartelement:(nsstring *)elementname namespaceuri:(nsstring *)namespaceuri qualifiedname:(nsstring *)qname attributes:(nsdictionary *)attributedict { if ([elementname isequaltostring:@"item"]) { isstatus = yes; currentpressrelease = [fcpressrelease alloc]; } if ([elementname isequaltostring:@"media:content"]) { ismedia = yes; media = [[nsmutabledictionary alloc] init]; [media setvalue:[attributedict valueforkey:@"url"] forkey:@"url"]; } } - (void)parser:(nsxmlparser *)parser didendelement:(nsstring *)elementname namespaceuri:(nsstring *)namespaceuri qualifiedname:(nsstring *)qname { if (isstatus) { if ([elementname isequaltostring:@"pubdate"]) { currentpressrelease.pubdate = currentnodecontent; } if ([elementname isequaltostring:@"title"]) { currentpressrelease.title = currentnodecontent; } if ([elementname isequaltostring:@"description"]) { currentpressrelease.summary = currentnodecontent; } if ([elementname isequaltostring:@"guid"]) { currentpressrelease.guid = currentnodecontent; } } if (ismedia) { if ([elementname isequaltostring:@"media:title"]) { [media setvalue:currentnodecontent forkey:@"title"]; } } if ([elementname isequaltostring:@"media:content"]) { [currentpressrelease.images addobject:media]; media = nil; } if ([elementname isequaltostring:@"item"]) { if (currentpressrelease != nil) { [self.posts addobject:currentpressrelease]; currentpressrelease = nil; currentnodecontent = nil; } else { currentpressrelease = nil; currentnodecontent = nil; } } }
fcpressrelease.h
@interface fcpressrelease : nsobject @property (strong, nonatomic) nsstring *pubdate; @property (strong, nonatomic) nsstring *title; @property (strong, nonatomic) nsstring *summary; @property (strong, nonatomic) nsstring *guid; @property (strong, nonatomic) nsmutablearray *images; @end
fcpressrelease.m
@implementation fcpressrelease @synthesize pubdate = _pubdate; @synthesize title = _title; @synthesize summary = _summary; @synthesize guid = _guid; @synthesize images = _images; @end
you should use init method complete initialization process fcpressrelease
currentpressrelease = [fcpressrelease alloc] init];
Comments
Post a Comment