Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the meaning of NSXMLParserErrorDomain error 5.?

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

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??

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.)
like image 869
mobibob Avatar asked Oct 22 '09 03:10

mobibob


3 Answers

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.

like image 114
Bdebeez Avatar answered Nov 07 '22 04:11

Bdebeez


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

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.
like image 30
Michael Z Avatar answered Nov 07 '22 04:11

Michael Z


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.

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.

I debugged by using the NSFileManager to iterate to my file and then verified that it was loadable with the contentsAtPath method. 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.

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.

like image 38
mobibob Avatar answered Nov 07 '22 02:11

mobibob