views:

2904

answers:

2

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

+1  A: 

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.

mobibob
BTW - I later did find the enumerations in the SDK documentation. It is very helpful, although not completely intuitive.
mobibob
+1  A: 

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.
Michael Z
Thanks Michael. Apparently the error is also returned when the filename is incorrect. The answer from Dave DeLong (see above) led me to my mistake. I also noted that I found the documentation.
mobibob