5

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.

pedroremedios
  • 763
  • 1
  • 11
  • 39

5 Answers5

5

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.

J. Cocoe
  • 881
  • 1
  • 10
  • 22
4

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).

Dan Waylonis
  • 802
  • 8
  • 11
  • +1, I found that I didn't have closing tags, so my XML wasn't well-formed either. – Kaydell Sep 21 '14 at 15:42
  • I used http://www.xmlvalidation.com/ to find my problem, it was definitely some dodgy XML that wasn't well-formed! – CMash Mar 12 '15 at 15:53
1

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.

user1118321
  • 25,567
  • 4
  • 55
  • 86
  • Is the code 111 supposed to be 11 then? I noticed there's no 111 defined in the documentation, which suggests to me that might be the case. – thegrinner Jul 08 '14 at 19:34
  • 1
    That's my guess. Either that or it's some internal error that Apple doesn't publish. – user1118321 Jul 09 '14 at 00:54
  • 3
    This isn't the correct answer, 111 is more likely caused by the XML not being well formed. Using http://www.xmlvalidation.com/ helped me to find my problem – CMash Mar 12 '15 at 15:52
0

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.

NSString *urlContents = [NSString stringWithContentsOfURL:mainUrl encoding:NSUTF8StringEncoding error:nil];
NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithData:[urlContents dataUsingEncoding:NSUTF8StringEncoding]];
Sam B
  • 27,273
  • 15
  • 84
  • 121
  • I tried that and I got `Error Domain=NSCocoaErrorDomain Code=-1 "The operation couldn’t be completed. (Cocoa error -1.)" UserInfo=0x8a50420 {NSXMLParserErrorMessage=Could not open data stream}`. – pedroremedios Dec 08 '13 at 15:35
0

I have recently ran into same error and found that the problem was invalid XML tags. There is no error on front-end code but the problem was at the backend site. To illustrate, my received XML data like this:

    <TABLE>
      <item>
           <0>memo</0>
           <1>179</1>
      </item>
    </TABLE>

And got error (NSXMLParseErrorDomain=111) when tried to parse the element that name tag is 0 or 1. Then I have changed the XML like this at the backend;

    <TABLE>
     <item>
        <name>memo</name>
        <weight>179</weight>
     </item>
    </TABLE>

Then parsing worked perfectly as the previous XML has invalid tag name.

Akif
  • 73
  • 5