打开文件时出现 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遍... 谢谢。
编辑: 当我尝试使用 [stringwithcontentofurl 编码错误] 方法在 NSString 中读取此内容时,我收到此错误:
错误域=NSCocoaErrorDomain Code=262 UserInfo=0x1006281c0 “ 文件无法打开,因为 不支持指定的 URL 类型。” 基本错误=(错误 域=NSURLErrorDomain 代码=-1002 UserInfo=0x1006280d0“不支持的 URL” 基本错误=(错误 域=kCFErrorDomainCFNetwork 代码=-1002 用户信息=0x100627d50 “不支持的网址”))
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 checked 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"))
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
调用 stringByExpandingTildeInPath 后添加
file://
:)Prepend
file://
after calling stringByExpandingTildeInPath :)前置文件:不是 file://
例如
Prepend file: not file://
for example