pedroremedios pedroremedios - 1 year ago 194
iOS Question

NSXMLParserErrorDomain 111

The code below is printing the following message:

Error Domain=NSXMLParserErrorDomain Code=111 "The operation couldn’t be completed. (NSXMLParserErrorDomain error 111.)

mainUrl = [NSURL URLWithString:@""];
NSString *urlContents = [NSString stringWithContentsOfURL:mainUrl encoding:NSISOLatin1StringEncoding error:nil];
NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithData:[urlContents dataUsingEncoding:NSISOLatin1StringEncoding]];
[xmlParser parse];
NSLog(@"%@", [xmlParser parserError]);

Anybody have a clue? As you can see by the code, the html is with ISO-8859-1 encoding.

Update: I submitted the url to the html validator site: and it found over 30 errors. I think that has something to do with the error. But I can parse the html just fine with HPPLE.

Answer Source

If you look in NSXMLParser.h, you'll see the list of error codes:

NSXMLParserInternalError = 1,
NSXMLParserOutOfMemoryError = 2,
NSXMLParserDocumentStartError = 3,
NSXMLParserEmptyDocumentError = 4,
NSXMLParserPrematureDocumentEndError = 5,
NSXMLParserInvalidHexCharacterRefError = 6,
NSXMLParserInvalidDecimalCharacterRefError = 7,
NSXMLParserInvalidCharacterRefError = 8,
NSXMLParserInvalidCharacterError = 9,
NSXMLParserCharacterRefAtEOFError = 10,
NSXMLParserCharacterRefInPrologError = 11,
NSXMLParserCharacterRefInEpilogError = 12,

So it looks like it's an NSXMLParserCharacterRefInPrologError, which is defined in the "Constants" section in the documentation. It says:

NSXMLParserCharacterRefInPrologError Invalid character found in the prolog. Available in iOS 2.0 and later. Declared in NSXMLParser.h.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download