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.
If you look in
NSXMLParser.h
, you'll see the list of error codes:So it looks like it's an
NSXMLParserCharacterRefInPrologError
, which is defined in the "Constants" section in the documentation. It says:I ran into something similar while parsing XML. The problem maybe the encoding that you are using. Try UTF8 enconding instead of iOSLatin i.e.
Seems nobody has stumbled on the correct answer yet, so here it is.
In NSXMLParserError docs, it says:
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: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.I also had the "111" (undocumented?) error code when parsing. It turns out that the XML Parser expects the XML to be well formed (e.g., one root node that contains all the others).