What is the meaning of NSXMLParserErrorDomain error 5.?
Asked Answered
E

3

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.)
Exude answered 22/10, 2009 at 3:30 Comment(0)
E
4

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.

Exude answered 22/10, 2009 at 3:32 Comment(2)
BTW - I later did find the enumerations in the SDK documentation. It is very helpful, although not completely intuitive.Exude
I had a similar problem because I was loading my file using [NSURL URLWithString:pathToFile]; 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. NO is also not working with me... still I am getting error no 5.Metabolize
F
15

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.

Feucht answered 27/11, 2010 at 13:37 Comment(1)
Yup! That difference is subtle and buried in the docs. Good idea to highlight. +1Exude
P
6

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.
Peltate answered 2/5, 2010 at 21:1 Comment(1)
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.Exude
E
4

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.

Exude answered 22/10, 2009 at 3:32 Comment(2)
BTW - I later did find the enumerations in the SDK documentation. It is very helpful, although not completely intuitive.Exude
I had a similar problem because I was loading my file using [NSURL URLWithString:pathToFile]; 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. NO is also not working with me... still I am getting error no 5.Metabolize

© 2022 - 2024 — McMap. All rights reserved.