title: Parsing XML with AFNetworking
body: <p>I am fairly new with iOS and is trying to do a REST request and fetch some XML data, parse that and ideally put into a custom Object. But for now I am stuck with the getting XML data.</p>
  
  <p>I found this code snippet on Github/AFNetworking..</p>
  
  <pre><code>- (void) fetchInterestData{
  AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
  manager.responseSerializer = [AFXMLResponseSerializer new];
  NSDictionary *parameters = @{@"foo": @"bar"};
  [manager POST:@"http://www.raywenderlich.com/downloads/weather_sample/weather.php?format=json" parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
      NSLog(@"JSON: %@", responseObject);
  } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
      NSLog(@"Error: %@", error);
  }];
  }
  </code></pre>
  
  <p>It works and fetches a JSON object. But I want to get the XML..</p>
  
  <p>If I use <a href="http://www.raywenderlich.com/downloads/weather_sample/weather.php?format=xml">http://www.raywenderlich.com/downloads/weather_sample/weather.php?format=xml</a> instead there is an xml object. But now the code breaks down completely. I was hoping to at least get the xml as a string object.</p>
  
  <p>What do I need to change to fetch the xml and assumingly I want to fetch a xml object of following structure:</p>
  
  <pre><code>&lt;RootNode&gt;
  &lt;Banks&gt;
    &lt;Bank&gt;
     &lt;BankId&gt;17&lt;/BankId&gt;
     &lt;BankName&gt;Bluestep&lt;/BankName&gt;
     &lt;BankUrl&gt;http://www.bluestep.se&lt;/BankUrl&gt;
     &lt;BankImage&gt;
     http://smartkalkyl.se/smartfiles/layout/banklogos/bluestep.png
     &lt;/BankImage&gt;
     &lt;Rates&gt;
         &lt;Rate&gt;
            &lt;RateDate&gt;2013-12-05&lt;/RateDate&gt;
            &lt;RateType&gt;5&lt;/RateType&gt;
            &lt;RateInterest&gt;6,23&lt;/RateInterest&gt;
            &lt;RateDescription/&gt;
            &lt;RateBefore&gt;6,27&lt;/RateBefore&gt;
            &lt;RateChange&gt;False&lt;/RateChange&gt;
            &lt;RateBeforeDate&gt;2013-08-13&lt;/RateBeforeDate&gt;
       &lt;/Rate&gt;
     &lt;/Rates&gt;
     &lt;/Bank&gt;
     &lt;Bank&gt;
     ...
  </code></pre>
  
  <p>How can I do that?</p>
  
  <p>UPDATE: New code..</p>
  
  <pre><code>AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
  AFHTTPRequestSerializer * requestSerializer = [AFHTTPRequestSerializer serializer];
  NSString *ua = @"Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5376e Safari/8536.25";
  [requestSerializer setValue:ua forHTTPHeaderField:@"User-Agent"];
  [requestSerializer setValue:@"application/xml" forHTTPHeaderField:@"Content-type"];
  manager.requestSerializer = requestSerializer;
  
  NSDictionary *parameters = @{@"foo": @"bar"};
  
  
  [manager POST:@"http://smartkalkyl.se/rateapp.aspx?user=xxxx&amp;pass=xxx"
     parameters:parameters
  success:^(AFHTTPRequestOperation *operation, id responseObject) {
      NSData * data = (NSData *)responseObject;
      self.fetchedXML = [NSString stringWithUTF8String:[data bytes]];
      //NSLog(@"Response string: %@", self.fetchedXML);
  }
  failure:^(AFHTTPRequestOperation *operation, NSError *error) {
      NSLog(@"Error: %@", error);
  }];
  </code></pre>
  
  <p>But this gives me an error..</p>
  
  <pre><code>2013-12-06 00:04:10.657 TabbedDemo[38335:a0b] Error: Error Domain=AFNetworkingErrorDomain Code=-1016 "Request failed: unacceptable content-type: text/xml" UserInfo=0x8d80ac0 {NSErrorFailingURLKey=http://smartkalkyl.se/rateapp.aspx?user=xxxx&amp;pass=xxxx, AFNetworkingOperationFailingURLResponseErrorKey=&lt;NSHTTPURLResponse: 0x8a75230&gt; { URL: http://smartkalkyl.se/rateapp.aspx?user=xxxx&amp;pass=xxxx } { status code: 200, headers {
  "Cache-Control" = private;
  "Content-Encoding" = deflate;
  "Content-Length" = 1260;
  "Content-Type" = "text/xml; charset=iso-8859-1";
  Date = "Thu, 05 Dec 2013 23:03:47 GMT";
  Server = "Microsoft-IIS/7.5";
  "Set-Cookie" = "ASP.NET_SessionId=ad3zikxbh4bcawxulkhwt2j3; path=/; HttpOnly";
  "X-AspNet-Version" = "4.0.30319";
  "X-Powered-By" = "UrlRewriter.NET 2.0.0, ASP.NET";
  } }, NSLocalizedDescription=Request failed: unacceptable content-type: text/xml}
  </code></pre>
  
  <p>Any idea what could be the problem?</p>
  
  <p>I am doing similar operation in the Android version of the app and this is the code that works there and that work. I never set any content type there..</p>
  
  <pre><code>// defaultHttpClient
  DefaultHttpClient httpClient = new DefaultHttpClient();
  HttpProtocolParams.setUserAgent(httpClient.getParams(),
  System.getProperty("http.agent"));
  HttpPost httpPost = new HttpPost(url);
  
  HttpResponse httpResponse = httpClient.execute(httpPost);
  HttpEntity httpEntity = httpResponse.getEntity();
  xml = EntityUtils.toString(httpEntity);
  </code></pre>