2011-10-20 18 views
0

iPhone開発に非常に新しいです。私はリソースフォルダにxmlファイルを持っています、そして、私のクライアントは毎日/週にxmlファイルを更新します。私は自分のURL(クライアントから)から新しいxmlファイルを保存し、その新しいxmlファイルをローカルに保存したいのと同時に、Resourceフォルダに保存されている古い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に保存)に苦労しています。誰も私を助けることができますか?私と貴重な時間を過ごしてくれてありがとう。私の問題を解決するための提案やサンプルコードをお聞かせください。もう一度私の貧しい英語を読んでくれてありがとう。

答えて

0

最も単純なXMLの解析は、TouchXMLを使用することをお勧めします。彼らのdocsをチェックしてください。

+0

ありがとうございます...非常に役に立ちます... – Gopinath

関連する問題