Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 809
user635064 Avatar asked Dec 09 '25 23:12

user635064


1 Answers

Prepend file:// after calling stringByExpandingTildeInPath :)

like image 94
Nick Weaver Avatar answered Dec 11 '25 12:12

Nick Weaver



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!