How to make a NSURL Request and parse the XML response?


   
#import "ViewController.h"
#import "XMLReader.h"


      
     //first you need to create a URL using String.
      NSURL *url = [NSURL URLWithString:@"feed://feeds.feedburner.com/blogspot/MKGLf?format=xml"];
           
      //Once you create a URL,you are ready make a request.
       NSURLRequest *request = [NSURLRequest requestWithURL:url];
        
       //After making request the apparent thing is expecting the response that may be expected response or an Error. so create those objects and initialize them with NULL.
        NSURLResponse *response = NULL;
NSError *requestError = NULL;
      //Once you have response with you, capture your responseData using NSData.
       NSData *responseData = [NSURLConnection sendSynchronousRequest:request        returningResponse:&response error:&requestError];

        //Convert the response data into response String.
NSString *responseString  = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];

        //Now you can start parsing the data using XML parser. You need XML parser in-order to     use the below class method "dictionaryForXMLString"
NSError *parserError = NULL;

      
NSDictionary *xmlDict = [XMLReader dictionaryForXMLString:responseString error:NULL]; 

        //Once You have xmlDict handy, you can pass this to the any ViewController(like tableview) to populate the data.

       

12 comments:

  1. Why don't you attack a library file here?

    ReplyDelete
  2. Can please attach the library file? or can explain the library file details?

    ReplyDelete
  3. • Nice and good article. It is very useful for me to learn and understand easily. Thanks for sharing your valuable information and time. Please keep updatingAzure Online course

    ReplyDelete
  4. Top SEO Company The best known mobile App design and development company based in Lahore Pakistan. Get applications for Android, iOS, HTML5, Windows.
    IOS Apps Development in Lahore

    ReplyDelete
  5. You post is very informative and contents are outstanding. Thanks for sharing such useful info.

    Zikia | OJOPLUS | Best Immune Booster Tablets in India

    ReplyDelete