Search code examples
iphoneyahoo-weather-api

Yahoo! weather in an iphone app


im developing an iphone app using yahoo weather service ( i have a key ). i have 2 question :

  1. can i use it in my app for commercial use ( like posting my app in appstore for free or no )
  2. why the xml and json result are different : http://weather.yahooapis.com/forecastrss?w=29330057&u=c and http://weather.yahooapis.com/forecastjson?w=29330057&u=c

there is any thing to do to much ( the first have the wanted location )? thank you.


Solution

  • I suspect this is an issue with XML namespaces. Depending on the framework used and the actual full XML you'd have to access the elements by their namespace. You might want to switch to another, DOM-based framework (not using NSXMLParser), for example GDataXMLNode by Google. In a DOM-based framework you can access the individual nodes in a tree-like structure instead of building one on your own.

    There are plenty of examples for this on the net, for example Building an RSS reader or How to read and write XML documents with GDataXML. But to give a quick example how this might look:

    NSError *error = nil;
    GDataXMLDocument *doc = [[GDataXMLDocument alloc] initWithData:data options:0 error:&error];
    
    if (doc == nil) { return nil; }
    
    NSMutableDictionary *result = [[NSMutableDictionary alloc] init];
    
    NSArray *lists = [doc nodesForXPath:@"/result/list" error:nil];
    if ([lists count] > 0)
    {
        for (GDataXMLNode *list in lists) {
            int listid = [self integerInNode:list forXPath:@"listid"];
            NSString *listname = [self stringInNode:list forXPath:@"name"];
    
            [result setValue:[NSNumber numberWithInt:listid] forKey:listname];   
    
        }     
    }
    [doc release];
    return [result autorelease];