xml NSXMLParserErrorDomain 错误 5. 是什么意思?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1604883/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the meaning of NSXMLParserErrorDomain error 5.?
提问by mobibob
Ok, I am back on this task. I have my XML properly download from my webserver with a URL pointing to the server's file, however, when I detect the network is 'unreachable' I simply point the URL to my application's local XML and I get the following error (N.B. the file is a direct copy of the one on the server).
好的,我又回到了这个任务上。我从我的网络服务器正确下载了我的 XML,其中的 URL 指向服务器的文件,但是,当我检测到网络“无法访问”时,我只是将 URL 指向我的应用程序的本地 XML,我收到以下错误(注意文件是服务器上的直接副本)。
I cannot find detail description, but I think it is saying that the URL is pointing to an inaccessible location. Am I storing this resource in the wrong location? I think I want it in the HomeDirectory / Library??
我找不到详细描述,但我认为它是说 URL 指向一个无法访问的位置。我是否将此资源存储在错误的位置?我想我想要它在 HomeDirectory / Library 中??
Debug output
调试输出
loadMyXml: /var/mobile/Applications/950569B0-6113-48FC-A184-4F1B67A0510F/MyApp.app/SampleHtml.xml 2009-10-14 22:08:17.257 MyApp[288:207] Wah! It didn't work. Error Domain=NSXMLParserErrorDomain Code=5 "Operation could not be completed. (NSXMLParserErrorDomain error 5.)" 2009-10-14 22:08:17.270 MyApp[288:207] Operation could not be completed. (NSXMLParserErrorDomain error 5.)
采纳答案by mobibob
According to Dave DeLong,
根据戴夫·德龙的说法,
That means it's having issues parsing your file.
这意味着它在解析您的文件时遇到问题。
I think it may be the XSLT reference in the XML - as it points to the webserver. I will review and get back to this question with an improved answer.
我认为它可能是 XML 中的 XSLT 引用 - 因为它指向网络服务器。我将回顾并以改进的答案回到这个问题。
It was the path of the file. My code wasn't even close to the right location -- and I was missing a trailing letter 's'. The error code definition implies a "premature end of file", which caused me to truncate my file without any success. I then went back to basics and iterated on the file system to look for my file.
这是文件的路径。我的代码甚至没有接近正确的位置——而且我遗漏了一个尾随字母“s”。错误代码定义意味着“文件过早结束”,这导致我截断了我的文件而没有任何成功。然后我回到基础并在文件系统上迭代以查找我的文件。
I debugged by using the NSFileManager to iterate to my file and then verified that it was loadable with the contentsAtPathmethod. I was able to dump it with NSLog(). Once I was convinced that the file was well-formed and loaded in raw form, I made certain that my NSURL was constructed with the same syntax and methods. Then it loaded correctly. Now I can load either a network file "full-featured" content or a local "sample" content.
我通过使用 NSFileManager 迭代到我的文件进行调试,然后验证它是否可以使用contentsAtPath方法加载 。我能够用 NSLog() 转储它。一旦我确信文件格式正确并以原始格式加载,我就确定我的 NSURL 是用相同的语法和方法构造的。然后它正确加载。现在我可以加载网络文件“全功能”内容或本地“样本”内容。
NSDirectoryEnumerator *dirEnumerator = [[NSFileManager defaultManager] enumeratorAtPath: NSHomeDirectory()];
NSString *something;
NSString *f;
while( something = [dirEnumerator nextObject] ) {
f = [[[NSString alloc] initWithFormat: @"%@/%@", NSHomeDirectory(), something] autorelease];
if( [f hasSuffix :@"two_cookies.xml"] ){
NSData *nsData = (NSData*) [[NSFileManager defaultManager] contentsAtPath: f];
NSLog(@"%@", nsData );
}
}
Output
输出
2009-10-22 00:47:40.147 MyApp[13843:20b] <?xml version="1.0" encoding="iso-8859-1"?>
P.S. I hope my being explicit here is helpful to others as they debug their data processing.
PS 我希望我在这里的明确对其他人在调试数据处理时有所帮助。
回答by Bdebeez
Along the same lines as the accepted answer, I had a similar problem because I was loading my file using:
与接受的答案相同,我遇到了类似的问题,因为我正在使用以下方法加载文件:
[NSURL URLWithString:pathToFile]; // **Wrong**
Instead, that should be:
相反,应该是:
[NSURL fileURLWithPath:pathToFile];
I too spent a long time looking at how my file might not be well formed, might be missing, etc before realizing that it was such a simple subtle difference.
在意识到这是一个如此简单的细微差别之前,我也花了很长时间查看我的文件可能格式不正确、可能丢失等。
回答by Michael Z
The explaination from Apple is: http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSXMLParser_Class/Reference/Reference.html#//apple_ref/doc/c_ref/NSXMLParserPrematureDocumentEndError
苹果的解释是:http: //developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSXMLParser_Class/Reference/Reference.html#//apple_ref/doc/c_ref/NSXMLParserPrematureDocumentEndError
Parser Error Constants
The following error types are defined by NSXMLParser.
typedef enum {
NSXMLParserPrematureDocumentEndError = 5
And the explaination of the error is:
错误的解释是:
NSXMLParserPrematureDocumentEndError
The document ended unexpectedly.
Available in Mac OS X v10.3 and later.
Declared in NSXMLParser.h.

