tags:

views:

36

answers:

1

Hello i am having problem in xml parsing, here I am not able to get the value of the particular tag. My code is as follows:

- (void)viewDidLoad {
    [super viewDidLoad];
    NSString *feedURLString = @"http://www.google.com/ig/api?weather=new+york,ny";
    NSURL *URL=[[NSURL alloc] initWithString:feedURLString];
    NSString *data=[[NSString alloc] initWithContentsOfURL:URL 
        encoding:NSASCIIStringEncoding error:nil];
    Element* root = [Element parseXML: data];
    NSArray* resultnode = [root selectElements:@"forecast_information"];
    for(Element *elementEntry in resultnode) {
       NSString *city_Data = [[NSString alloc]init ];
       //if([elementEntry isEqualToString:@"city_data"] )
       city_Data =  [[elementEntry selectElement:@"city data"]contentsText];
       NSLog(@"city_Data======>>>>>%@",city_Data);
    }
}

here i want the value of city data tag which has the value as New York, NY whenever i print the value of string it is always nil. Thansk in advance.

+1  A: 

XML nodes never ever have spaces in their names. You want to load the Element named "city" and that node contains an attribute named "data".

I didn't check your code in detail... hope the rest is working.

Daniel Bleisteiner
i tried with the "city" but didnt get success you can take a look at the url which is "www.google.com/ig/api?weather=new+york,ny" ,just tell me what to change in this line of code city_Data = [[elementEntry selectElement:@"city data"]contentsText];
mrugen
If you open the XML you'll notice the structure with <xml_api_reply> ... <weather> ... <forecast_information> and finally <city> inside. So you normally need to traverse that tree to find the node you're looking for. That node has an attribute named data. Also have a look at the NSXMLParser class reference from Apple. I'm not even sure which framework you are trying to use here.
Daniel Bleisteiner
Here i am using libxml can you just he figure it out where i need to make changes.
mrugen