2011-10-20 2 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을 읽거나 구문 분석하는 방법에 어려움을 겪고 있습니다 (From URL 및 fileManager에 저장 됨). 누구든지 제발 도와 주실 래요? 저와 함께 귀중한 시간을 보내 주셔서 감사합니다. 내 문제를 해결하기 위해 제안이나 샘플 코드를 제공해 주시겠습니까? 다시 한번 가난한 영어를 읽어 주셔서 감사합니다.

답변

0

가장 간단한 XML 구문 분석은 TouchXML을 사용하는 것이 좋습니다. 그들의 docs을 확인하십시오.

+0

감사합니다 ... 매우 도움이됩니다 ... – Gopinath

관련 문제