How do you save the text from a webview into an xml in the application documents directory? I want to do this so I can let the user save an article for a blog app in the iPhone to read even when the iPhone has no network signal.
Here is the code I have for the WebView that loads the original article.
Here is the viewDidLoad I have for the controller I want to load the articles:
Does this look like it is anywhere close to where it should be?
Ok, I realize a few things about why this will not work, but not 100% sure how to proceed. I was able to open the applications document directory and view the sample.xml file it created, which had errors when tried to open. I realize that this method won't work because it is just writing the URL to the xml and then trying to parse it again, so I would still need internet. What would be the best way to go about doing this right?
Here is the code I have for the WebView that loads the original article.
Code:
-(IBAction)save {
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:_entry.articleUrl]];
NSString *applicationDocumentsDir =
[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
NSString *storePath = [applicationDocumentsDir stringByAppendingPathComponent:@"sample.xml"];
// write to file atomically (using temp file)
[data writeToFile:storePath atomically:TRUE];
}
Here is the viewDidLoad I have for the controller I want to load the articles:
Code:
- (void)viewDidLoad {
[super viewDidLoad];
[activity startAnimating];
self.title = @"Saved Articles!";
self.allEntries = [NSMutableArray array];
self.queue = [[[NSOperationQueue alloc] init] autorelease];
self.feeds = [NSArray arrayWithObjects:@"sample.xml",
nil];
[self refresh];
}
Ok, I realize a few things about why this will not work, but not 100% sure how to proceed. I was able to open the applications document directory and view the sample.xml file it created, which had errors when tried to open. I realize that this method won't work because it is just writing the URL to the xml and then trying to parse it again, so I would still need internet. What would be the best way to go about doing this right?
Last edited: