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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T13:42:02+00:00 2026-06-06T13:42:02+00:00

I am trying to use NSXMLParser to parse an XML file that looks something

  • 0

I am trying to use NSXMLParser to parse an XML file that looks something like this:

<?xml version="1.0" encoding="us-ascii"?>
<teams>
    <team id = "A1">
        <player1>John</player1>
        <player2>José</player2>
    </team>
    ...
</teams>

I use the following code:

NSString *urlString = [NSString stringWithFormat:@"http://www....abc.php?category=%@&poule=%c", @"S", 'B'];  // Obviously, this contains an actual web address
NSURL *url = [NSURL URLWithString:urlString];
NSData *xml = [[NSData alloc] initWithContentsOfURL:url];   // <==
NSXMLParser *xmlParserObject = [[NSXMLParser alloc]initWithData:xml];
[xmlParserObject setDelegate:self];
[xmlParserObject parse];

and I implemented the didStartElement, foundCharacters, didEndElement and the parserErrorOccurred delegate functions.

This all goes well until a ‘special’ character, such as an é is encountered. The delegate method parserErrorOccurred reports the following error:

parser error: Error Domain=NSXMLParserErrorDomain Code=1544 "The operation couldn’t be completed. (NSXMLParserErrorDomain error 1544.)"
parser error: Error Domain=NSXMLParserErrorDomain Code=5 "The operation couldn’t be completed. (NSXMLParserErrorDomain error 5.)"

Then I replaced the part marked with ‘<==’ with the following:

NSError *error;
NSData *xml = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:&error];
if (xml == nil) {
    NSLog(@"*** Fatal error: %@\nuserInfo:%@", error, [error userInfo]);
}

and got the following error in addition to the one above:

 *** Fatal error: Error Domain=NSCocoaErrorDomain Code=261 "The operation couldn’t be completed. (Cocoa error 261.)" UserInfo=0x8158d90 {NSURL=http://www....abc.php?category=S&poule=B, NSStringEncoding=4}
userInfo:{
    NSStringEncoding = 4;
    NSURL = "http://www....abc.php?category=S&poule=B";
}

I also tried replacing the NSUTF8StringEncoding with any of the other encoders, such as NSISOLatin1StringEncoding, NSUTF16StringEncoding, NSASCIIStringEncoding, NSUnicodeStringEncoding and more. This resulted in the following error:

 -[__NSCFString bytes]: unrecognized selector sent to instance 0x6e4cbc0
 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString bytes]: unrecognized selector sent to instance 0x6e4cbc0'
*** First throw call stack:
(0x12d0022 0x1781cd6 0x12d1cbd 0x1236ed0 0x1236cb2 0xce5f51 0xb447 0xaa89 0x1f2e330 0x1f2f439 0x908b9b24 0x908bb6fe)
terminate called throwing an exception(lldb) 

I have no control over the contents of the XML, but if it indeed contains incorrect information, then maybe I can talk to the webmaster.

I’m fine with displaying the é character as ‘e’ or ‘?’ if that’s what it takes.

Any advice on what causes this error and how to correct or bypass it is greatly appreciated.

Tx!

–GB

  • 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-06-06T13:42:03+00:00Added an answer on June 6, 2026 at 1:42 pm

    I found a bypass (not a solution) to this problem. To get from the NSURL to the NSData, I have used the following code:

            NSError *error;
            NSString *xmlText = [NSString stringWithContentsOfURL:url encoding:NSASCIIStringEncoding error:&error];
            xmlText = [xmlText stringByReplacingOccurrencesOfString:@"é" withString:@"e"];
            NSData *xml = [xmlText dataUsingEncoding:NSASCIIStringEncoding];
    

    So basically, I

    • Converted the NSURL in an NSString
    • Edited that string by replacing the ‘special’ characters
    • Used the edited string to create the NSData

    I also found that I had to use NSASCIIStringEncoding instead of NSUTF8StringEncoding (which is what the XML specifies, but which failed earlier).

    Anyway, suggestions to really solve the problem are still welcome, but this bypass works for me for the time being…

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

Sidebar

Related Questions

I'm trying to use an NSXMLParser to parse a property file that is related
I am Trying To Use NSXMLParser to parse an xml file using cocoa which
ok so I am trying to parse XML data into a table, this is
I am trying to parse a an xml file. I am creating an array
I'm trying use epoch time dates in my series data. The array looks like
I'm using NSXMLParser to parse a small XML file containing information about videos. One
I'm trying use this code to get image resolution from file bool GetImageSizeEx(const char
I'm trying use mod_rewrite to rewrite URLs from the following: http://www.site.com/one-two-file.php to http://www.site.com/one/two/file.php The
Trying to use this method (gist of which is use self.method_name in the FunnyHelper
Trying to use GnuPG with Delphi (Win32). I need to sign some file with

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.