0
對於iPhone開發來說,這是非常新的東西。我在Resource文件夾中有一個xml文件,那麼我的客戶端將每天/每週更新xml文件。我想從他們的URL(從客戶端)存儲新的XML文件,並在本地存儲新的XML文件,同時我需要刪除存儲在資源文件夾中的舊文件。我已經按照下面的代碼,但我現在掙扎着檢索存儲的新XML以及如何解析這個新的XML文件。如何解析存儲在本地iphone中的xml文件?
NSArray *xmlpaths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *cachdirectory = [[NSString alloc] initWithString:[xmlpaths objectAtIndex:0]];
//first save your file from resource directory to app's cache directory
NSString *path = [[NSBundle mainBundle] pathForResource:@"Directory" ofType:@"xml"];
NSData *filedata = [NSData dataWithContentsOfFile:path];
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *saveName = [cachdirectory stringByAppendingPathComponent:@"NewDirectory.xml"];
[fileManager createFileAtPath:saveName contents:filedata attributes:nil];
//remove file from resource directory
[fileManager removeItemAtPath:path error:nil];
//new file from internet is avilable then do following:first remove old file from cache
[fileManager removeItemAtPath:cachdirectory error:nil];
//save new file from internet
NSData *newfiledata=[NSData dataWithContentsOfURL:[NSURL URLWithString:UrlString]];
[fileManager createFileAtPath:savename contents:newfiledata attributes:nil];
我遵循此代碼。現在我正在努力如何讀取/解析這個新的xml(從Url並保存在fileManager中)。任何人都可以幫助我嗎?感謝您花費寶貴的時間陪伴我。請提供任何建議或任何示例代碼來解決我的問題?我再一次感謝你閱讀我可憐的英語。
謝謝...這是非常有用的... – Gopinath