NSXMLParserErrorDomain 111

纵然是瞬间 提交于 2019-12-01 19:16:53

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.

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

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.

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]];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!