Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 954565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T00:14:09+00:00 2026-05-16T00:14:09+00:00

i want to parse google weather API using NSXML so please give me some

  • 0

i want to parse google weather API using NSXML so please give me some Guidance for this.

This is My url

and i have taken such kind of steps:

NSURL *url = [NSURL URLWithString:@"http://www.google.com/ig/api?weather=Ahemdabad"];

 NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
 [theRequest setHTTPMethod:@"POST"];
 NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];

 if(theConnection){
  webData = [[NSMutableData data] retain];
  NSLog( @"connection established");
 }
 else {
  NSLog(@"theConnection is NULL");
 }
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
 [webData setLength: 0];
}

-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
 [webData appendData:data]; 
}

-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
 NSLog(@"ERROR with theConenction");
 [connection release];
 [webData release];
}

-(void)connectionDidFinishLoading:(NSURLConnection *)connectio   
{     
    NSLog(@"DONE. Received Bytes: %d", [webData length]);

 NSString *theXML = [[NSString alloc] initWithBytes: [webData mutableBytes] length:[webData length] encoding:NSUTF8StringEncoding];
 NSLog(@"thexml=============>%@", theXML);
 [theXML release];


 if(parser)
 {
  [parser release];
 }

 parser = [[NSXMLParser alloc]initWithData:webData];
 [parser setDelegate: self];
 [parser setShouldResolveExternalEntities: YES];
 [parser parse];

 [connection release];
 [webData release];

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T00:14:11+00:00Added an answer on May 16, 2026 at 12:14 am

    hey ankit you can get this code if at all its helpful to you no need to establish connection

    just use this method

    -(id)initWithURL:(NSURL*)url arrayRootObjectTags:(NSArray*)arrTags sel:(SEL)seletor andHandler:(NSObject*)handler{
        if(self = [super init] ){
            self.mainArray=arrTags;
            self.MainHandler=handler;
            self.targetSelector=seletor;
            NSLog(@"%@",[url description]);
            NSURLRequest *req=[NSURLRequest requestWithURL:url cachePolicy:NSURLCacheStorageNotAllowed timeoutInterval:30];                 
            con=[[NSURLConnection alloc] initWithRequest:req delegate:self];
            if(con){
                myWebData=[[NSMutableData data] retain];
            } else {
                [MainHandler performSelector:@selector(targetSelector:) withObject:nil];
            }
        }
        return self;
    }
    

    also the other supporting method

    -(void)parser:(NSXMLParser*)parser didStartElement:(NSString*)elementName namespaceURI:(NSString*)namespaceURI qualifiedName:(NSString*)qualifiedName attributes:(NSDictionary*)attributeDict {
        if([elementName isEqualToString:@"html"] || [elementName isEqualToString:@"HTML"]){
            didGetHTML=YES; [self parserDidEndDocument:parser];
        } else if([[mainArray objectAtIndex:0] isEqualToString:elementName] && [[mainArray objectAtIndex:1] isEqualToString:elementName] && !didGetHTML) {
            objectsArray=[[NSMutableArray alloc] init];
            tmpD=[[NSMutableDictionary alloc] init];
            if(tmpOther==nil) tmpOther=[[NSMutableDictionary alloc] init];      
        } else if([[mainArray objectAtIndex:0] isEqualToString:elementName] && !didGetHTML ) {
            objectsArray=[[NSMutableArray alloc] init];
            if(tmpOther==nil) tmpOther=[[NSMutableDictionary alloc] init];      
        } else if([[mainArray objectAtIndex:1] isEqualToString:elementName] && !didGetHTML ) {
            tmpD=[[NSMutableDictionary alloc] init];
        } else if([mainArray containsObject:elementName] && !didGetHTML){
            [tmpD setValue:[attributeDict valueForKey:@"data"] forKey:elementName];
        }
    }
    

    -(void)parser:(NSXMLParser*)parser foundCharacters:(NSString*)string {
    if(tmpString==nil && !didGetHTML){
    tmpString=[[NSString alloc] initWithString:string];
    } else if(!didGetHTML){
    NSString *t=[NSString stringWithString:tmpString];
    if([tmpString retainCount]>0) { [tmpString release]; tmpString=nil; }
    tmpString=[[NSString alloc] initWithFormat:@”%@%@”,t,string];
    }
    }

    -(void)parser:(NSXMLParser*)parser didEndElement:(NSString*)elementName namespaceURI:(NSString*)namespaceURI qualifiedName:(NSString*)qualifiedName {
        if([[mainArray objectAtIndex:0] isEqualToString:elementName] && [[mainArray objectAtIndex:1] isEqualToString:elementName] && !didGetHTML){
            [objectsArray addObject:tmpD];
        } else if([elementName isEqualToString:[mainArray objectAtIndex:1]] && !didGetHTML){
            [objectsArray addObject:tmpD];
            [tmpD release]; tmpD=nil;
        } else if([mainArray containsObject:elementName] && !didGetHTML) {
            if(![tmpD valueForKey:elementName]){
                [tmpD setValue:tmpString forKey:elementName];
            }
            [tmpString release]; tmpString=nil;     
        } else {
            [tmpOther setValue:tmpString forKey:elementName];
            [tmpString release]; tmpString=nil;
        }
    }
    

    and simply call the initwith url method from which ever class you have written this method

    just you have to give root tag object tag and element tag of a particular object tag and also give selector after that take the response in dictionary and they take it in array and display the result according to your value for key

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 486k
  • Answers 486k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer This sounds like something your build tool should provide you… May 16, 2026 at 7:58 am
  • Editorial Team
    Editorial Team added an answer Try a framework, like CakePHP or Symfony. Almost all frameworks… May 16, 2026 at 7:58 am
  • Editorial Team
    Editorial Team added an answer x->y means (*x).y. In other words, "take the address pointed… May 16, 2026 at 7:58 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.