首先H文件: NSMutableArray *rssList; M文件,开始解析: - (void)applicationDidFinishLaunching:(UIApplication *)application { // Add the tab bar controller's current view as a subview of the window [window addSubview:tabBarController.view]; rssList = [[NSMutableArray alloc] initWithCapacity:1]; NSString *urlz=[NSString stringWithFormat:@"http://xml.weather.yahoo.com/forecastrss?p=CHXX0037&u=c"]; NSXMLParser *firstParser = [[NSXMLParser alloc] initWithContentsOfURL:[NSURL URLWithString:urlz]]; [firstParser setDelegate:self]; [firstParser parse]; } 解析方法: - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *) qualifiedName attributes:(NSDictionary *)attributeDict { if ([elementName compare:@"yweather:condition"] == NSOrderedSame) { [rssList addObject:[[NSDictionary alloc] initWithObjectsAndKeys: [attributeDict objectForKey:@"code"],@"code", [attributeDict objectForKey:@"temp"],@"temp", nil]]; } } -(void)parserDidEndDocument:(NSXMLParser *)parser{ [parser release]; } 获得数据: navlabel = [[UILabel alloc] initWithFrame:CGRectMake(240, 20, 80, 42)]; navlabel.backgroundColor = [UIColor colorWithRed:0.85 green:0.90 blue:0.90 alpha:0]; navlabel.text = [@"广州/n" stringByAppendingString:[[[rssList objectAtIndex:0] objectForKey:@"temp"] stringByAppendingString:@"度"]]; navlabel.numberOfLines = 2; navlabel.font = [UIFont systemFontOfSize:12]; navlabel.textColor = [UIColor colorWithRed:0.99 green:0.99 blue:0.99 alpha:0.8]; [self.window addSubview:navlabel]; UIImageView *imgz = [[UIImageView alloc] initWithFrame: CGRectMake(270, 17, 44,44)]; imgz.image = [UIImage imageNamed:[[[rssList objectAtIndex:0] objectForKey:@"code"] stringByAppendingString:@".gif"]]; [self.window addSubview:imgz]; [imgz release];