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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:03:41+00:00 2026-05-15T20:03:41+00:00

Currently I am trying to parse an xml string that I already have (no

  • 0

Currently I am trying to parse an xml string that I already have (no web calls needed). My app is native iPhone in Objective-C. I have set up an NSXMLParser delegate class which uses initWithData:xmlData. For some reason, the first and only callback on my delegate is to parser: parseErrorOccurred with the following text:

"Unable to download content from web site (Error code 5 )"

Obviously, this makes no sense since I don’t ask for anything from the web. Might it still be using some private URL property to call out for something?

Here is some code:

Delegate Class XmlParser:

- (void)parseXmlString:(NSString *)xml parseError:(NSError **)error {
    DEBUG_NSLog(@"XML Parser: Called with string: %@", xml);

    NSData *xmlData = [xml dataUsingEncoding:NSASCIIStringEncoding];
    NSXMLParser *parser = [[NSXMLParser alloc] initWithData:xmlData];

    // Set self as the delegate of the parser so that it will receive the parser delegate methods callbacks.
    if (parser != nil) {
        [parser setDelegate:self];
        [parser setShouldProcessNamespaces:NO];
        [parser setShouldReportNamespacePrefixes:NO];
        [parser setShouldResolveExternalEntities:NO];
        [parser parse];

        NSError *parseError = [parser parserError];
        if (parseError && error) {
            *error = parseError;
        }

        [parser release];
    }
}

Called from:

XmlParser *parser = [[XmlParser alloc] init];
NSError *error = nil;
[parser parseXmlString:aString parseError:&error];
if (error) {
  DEBUG_NSLog(@"ERROR FROM PARSER");
}

where aString is an NSString containing XML (note: without header).

Error callback that is called:

- (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError {
    NSString * errorString = [NSString stringWithFormat:@"Unable to download content from web site (Error code %i )", [parseError code]];
    DEBUG_NSLog(@"XML Parser ERROR: %@", errorString);
    [parser abortParsing];
}

When the code is run, the parseErrorOccurred hits immediately after [parser parse], and yes, I have implemented each of the didStartDocument, didEndDocument, etc.

Thanks!

UPDATE:

In debugging it seems that the xmlData object that I create is 0 bytes, even though the xml string I pass in to dataUsingEncoding has plenty of data. Is the encoding the issue?

One of the xml elements contains nested html. I’m thinking that the “s and &’s could be a problem. Hopefully doing a “->\” will fix it.

Neither escaping the quotes or replacing any &s with & fixed the problem. Could there be something wrong with having a tag in the string?

  • 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-15T20:03:42+00:00Added an answer on May 15, 2026 at 8:03 pm

    Your error message is hiding the actual error. Your xmlstring appears to be invalid as the error code is “Error code 5”. See this other SO question. NSXMLparser errorcode 5

    Update

    When creating your xmlData instance use NSUTF8StringEncoding instead of NSASCIIStringEncoding
    If that stil fails, post the actual string. Passing an empty data object to the parser is causing the error.

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

Sidebar

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.