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:@"http://www.carris.pt/pt/carreiras"];
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: http://validator.w3.org/ 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.
Seems nobody has stumbled on the correct answer yet, so here it is.
In NSXMLParserError docs, it says:
The following error codes are defined by NSXMLParser. For error codes not listed here, see the <libxml/xmlerror.h> header file.
The number 111 isn't mentioned in this list, so we go to /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/libxml2/libxml/xmlerror.h
, and find the value:
XML_ERR_USER_STOP, /* 111 */
There isn't a lot of documentation on XML_ERR_USER_STOP
in libxml2, but from reading the changeset, it looks like it's a fast-fail when the parser sees an unexpected EOF.