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 6679151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:19:34+00:00 2026-05-26T04:19:34+00:00

I have an iOS app that is calling a web service for some XML

  • 0

I have an iOS app that is calling a web service for some XML data as such:

NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithContentsOfURL:xmlURL];
[xmlParser setDelegate:self];
[xmlParser setShouldProcessNamespaces:NO];
[xmlParser setShouldReportNamespacePrefixes:NO];
[xmlParser setShouldResolveExternalEntities:NO];        
[xmlParser parse];

I kept getting an error:

Error parsing XML: The operation couldn’t be completed. 
(NSXMLParserErrorDomain error 31.)

Error 31 is “NSXMLParserUnknownEncodingError”. I sniffed the HTTP response in WireShark and it turns out the web service is sending “Content-Encoding: gzip” with GZIP’d data in the body and the reason it’s doing that is because the request being sent from iOS sets “Accept-Encoding: gzip, deflate” in the HTTP headers. It seems the initWithContentsOfURL tells webservers it can handle gzip’d data when it actually can’t.

I’m guessing I need to load the web server response into NSData then run it through a decompressor method to get a NSString and then pass that string to the NSXMLParser.

My question is, what’s the best way to do this decompression? ZLib? Any issues linking to ZLib from within iOS?

Thank you,
Stateful

P.S. I tagged this with osx too since I imagine this problem would be there as well, since NSXMLParser is a Foundation class.

  • 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-26T04:19:34+00:00Added an answer on May 26, 2026 at 4:19 am

    Use NSURLConnection delegate methods to download response from webservice. then pass the data to NSXMLParser initWithContentsOfData.
    By using NSURLConnection delegate methods (asynchronous connection) you are not blocking the current thread. This is recommended way to download response. Plus NSURLConnection uncompressses(deflates) g-zip compressed response. you don’t need to do anything special to deflate it.
    And you can inspect the data before giving it to NSXMLParser ( Thanks Steven ).

    Using NSXMLParser initWithContentsOfURL should be mostly used to parse XML files within your Application (in your resources or documents sections). It surely makes connection with your webservice to download response BUT it is equivalent to synchronous call and blocks your thread.
    Avoid NSURLConnection sendSynchronous and initWithContentsOfURL to pass remote webservice URL.

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

Sidebar

Related Questions

I have an iOS app that contains a lot of local web content. Some
I have an iOS app that stores some data in a sqlite database. The
I have an iOS app that connects to a server periodically looking for data
I have a Rails web app that is used to gather data from an
My app is crashing in iOS 5 because I have some code that is
I have an app that runs on iPad and iPhone running iOS 3.2, but
I have an iOS app that displays content from a sqlite db in a
I have an iOS 5 App that consumes webservices from a Rails 3 server.
I have a titanium based iOS app that basically is following my own MVC
I have an iOS app that posts to users FB feeds with a link,

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.