I am trying to parse google weather API. I am using nsxml parser to get dates, weather etc from the api and then I store them in Core Data.
What I am trying to do is extract dates up from the parser, match them with the current date and then store only as many information we need to store.
Say, today's date is 08/09/2011 and a date from the parse matches. I wish to store only 2 information from the parser into Core Data. I am trying to store only those dates but I am getting all 4 information to be stored into Core Data.
If I give 08/11/2011, I should be only getting 3 days of information not 4. But I am unable to do that. I am posting my sample code. I am using testcase to check my application.
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict
{
if ([@"forecast_date" isEqualToString:elementName])
{
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyy-MM-dd"];
startDate = [formatter dateFromString:[attributeDict objectForKey:@"data"]];
[formatter release];
}
else if ([@"forecast_conditions" isEqualToString:elementName])
{
isParsingForecast = YES;
isParsingInformation = NO;
isParsingCurrent = NO;
newdate=[startDate addTimeInterval:60*60*24*[forecastConditions count]];
NSMutableDictionary *fields = [[NSMutableDictionary alloc] init];
[fields setObject:newdate forKey:@"date"];
[fields setObject:city forKey:@"city"];
[fields setObject:state forKey:@"state"];
[fields setObject:country forKey:@"country"];
[fields setObject:startDate forKey:@"startdate"];
//[fields setObject: forKey:<#(id)#>]
[forecastConditions addObject:fields];
[fields release];
}
else if (isParsingForecast) {
NSMutableDictionary *fields = [forecastConditions lastObject];
NSLog(@"dic is : %@ \n\n",fields);
[fields setObject:[attributeDict objectForKey:@"data"] forKey:elementName];
}
}
Posted my whole code here http://www.iphonedevsdk.com/forum/iphone-sdk-development/87475-coredata-storing-more-values-than-what-required-store-database.html#post363100