开发者

NSXMLDocument error with opening file

I am trying to read a file into NSXMLDocument. Here my code:

NSString *urlString = [@"~/Library/Preferences/Quark/QuarkXPress 8/OutputStyles.xml" stringByExpandingTildeInPath];
urlString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *url = [NSURL URLWithString:urlString];

NSError *error = nil;

NSXMLDocument *doc = [[NSXMLDocument alloc] initWithContentsOfURL:url options:0 error:&error];
NSLog(@"%@", error);
NSLog(@"%@", doc);

but, in console I get:

2011-04-19 07:41:09.914 XMLTest[1409:a0f] Error Domain=NSURLErrorDomain Code=-1014 UserInfo=0x1001289d0 "zero byte resource"
2011-04-19 07:41:09.915 XMLTest[1409:a0f] (null)

Any suggestion about what could be wrong? I have the file there..I c开发者_开发技巧hecked it like a 100 times... Thanks.

EDIT: When I try to read this in a NSString using [stringwithcontentofurl encoding error] method i get this error:

Error Domain=NSCocoaErrorDomain Code=262 UserInfo=0x1006281c0 "The file couldn’t be opened because the specified URL type isn’t supported." Underlying Error=(Error Domain=NSURLErrorDomain Code=-1002 UserInfo=0x1006280d0 "unsupported URL" Underlying Error=(Error Domain=kCFErrorDomainCFNetwork Code=-1002 UserInfo=0x100627d50 "unsupported URL"))


Prepend file:// after calling stringByExpandingTildeInPath :)


Prepend file: not file:// for example

NSURL *url = [NSURL URLWithString:([NSString stringWithFormat:@"file:/Users/name/Desktop/%@",fileName])];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜