hi all,
I have a problem in parsing xml from google api, the api xml looks like this
.......
Now the problem is that first of all, the tags are different, like first parent tag name is "abc" and second parent tag is "efg", further more the inner tags are different as well.
i have modified code got from web that it parses another url, but in this case since the tags keeps on changing it does not work.
the url = "http://www.google.com/ig/api?weather=anaheim,ca"
Source Code
(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{
//NSLog(@"found this element: %@", elementName);
if (currentElement) {
[currentElement release];
currentElement = nil;
}
currentElement = [elementName copy];
NSString *thisOwner = [attributeDict objectForKey:@"data"];
NSLog(@"element Name-------: %@", thisOwner);
if ([elementName isEqualToString:@"forecast_information"]) //|| [elementName isEqualToString:@"current_conditions"] || [elementName isEqualToString:@"forecast_conditions"])
{
// clear out our story item caches...
//NSString *nm = [[attributeDict objectForKey:@"city"] stringValue];
//NSLog(@"value...%@",nm);
item = [[NSMutableDictionary alloc] init];
currentTitle = [[NSMutableString alloc] init];
currentDate = [[NSMutableString alloc] init];
currentSummary = [[NSMutableString alloc] init];
currentLink = [[NSMutableString alloc] init];
[item setObject:currentLink forKey:@"postal_code"];
[item setObject:currentSummary forKey:@"current_date_time"];
[item setObject:currentDate forKey:@"unit_system"];
NSLog(@"adding story: %@", currentTitle);
[stories addObject:[item copy]];
}
}
I have another function didEndElement where the values are assigned in the array,
but i could not figure out how to assign values of an attribute. Can somebody please help me in this regards
Thanks!