2011-10-20 52 views
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中)。任何人都可以帮助我吗?感谢您花费宝贵的时间陪伴我。请提供任何建议或任何示例代码来解决我的问题?我再一次感谢你阅读我可怜的英语。

回答

相关问题