NSXMLParserErrorDomain 111
Asked Answered
P

5

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.

Phagocyte answered 8/12, 2013 at 15:3 Comment(1)
I have seen it pop up while parsing a CDATA tag with invalid UTF-8 characters.Centrosphere
U
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.

Usurer answered 19/7, 2016 at 23:57 Comment(0)
V
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).

Vimen answered 24/7, 2014 at 2:7 Comment(2)
+1, I found that I didn't have closing tags, so my XML wasn't well-formed either.Chayachayote
I used xmlvalidation.com to find my problem, it was definitely some dodgy XML that wasn't well-formed!Abysm
B
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.

Buzzard answered 8/12, 2013 at 15:15 Comment(3)
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.Bailsman
That's my guess. Either that or it's some internal error that Apple doesn't publish.Buzzard
This isn't the correct answer, 111 is more likely caused by the XML not being well formed. Using xmlvalidation.com helped me to find my problemAbysm
B
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]];
Bolshevist answered 8/12, 2013 at 15:29 Comment(1)
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}.Phagocyte
U
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.

Undercurrent answered 31/8, 2021 at 12:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.