gpt4 book ai didi

objective-c - 打开文件时出现 NSXMLDocument 错误

转载 作者:搜寻专家 更新时间:2023-10-30 19:56:55 24 4
gpt4 key购买 nike

我正在尝试将文件读入 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 encoding error] 方法在 NSString 中读取此内容时,出现此错误:

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

最佳答案

在调用 stringByExpandingTildeInPath 之后添加 file:// :)

关于objective-c - 打开文件时出现 NSXMLDocument 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5715820/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com