Load XML from documents directory - iPhone
Instead o开发者_如何学编程f loading a XML from the URL, I would like to load it from the documents directory(which i saved when there is Internet connection)
NSString* filename=@"magzine.xml";
NSData *data=[NSData dataWithContentsOfURL:[[NSURL alloc] initWithString:[URLlink stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];
NSString *applicationDocumentsDir =[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
NSString *storePath = [applicationDocumentsDir stringByAppendingPathComponent:filename];
[data writeToFile:storePath atomically:YES];
NSLog(@"URL: %@",url);
xmlParser = [[NSXMLParser alloc] initWithContentsOfURL:url];
//xmlParser = [[NSXMLParser alloc] initWithContentsOfFile:filename];
[xmlParser setDelegate:self];
[xmlParser parse];
Now i am getting the xml from url ,that is from initwithcontentsofurl,Now i want to get the saved file from documents directory when there is no internet connection.Please help me in this ,how to load the xml?? THANKS IN ADVANCE
Here is an example on how to load and parse local XML files on the iPhone.
精彩评论