我正在尝试将文件读入NSXMLDocument。在这里我的代码:NSXMLDocument打开文件时出错
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);
但是,在控制台我得到:
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)
什么可能是错的任何建议?我有那里的文件..我检查它像100次... 谢谢。
编辑: 当我尝试使用一个的NSString阅读本[stringwithcontentofurl编码错误]方法我得到这个错误:
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"))
Try @“〜/ Library/Preferences/Quark/QuarkXPress \ 8/OutputStyles.xml “ 请。 – 2011-04-19 11:56:26
Nop不起作用。而且我还会收到未知转义序列的警告。感谢您的输入。 – user635064 2011-04-19 12:03:43
和@“〜/ Library/Preferences/Quark/QuarkXPress 8/OutputStyles.xml”,在那个URL字符串中有一个//现在没有引用空格。 – 2011-04-19 12:08:38