2010-11-23 3 views
2

UTF-8 형식의 xml을 포함하고있는 로컬 XML 파일이 있습니다. 그러나 NSXMLParser는 correclty를 구문 분석하지 않습니다.로컬 XML 파일을 읽으면 NSXMLParser가 NULL을 반환합니다.

경로 파일로 :

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *documentsDirectory = [paths objectAtIndex:0]; 
NSString *appFile = [documentsDirectory stringByAppendingPathComponent:@"example.xml"]; 

웹에서 XML을 저장 : 내가 직접 "XML"그것을 NSURL을 구문 분석하려고하면

NSURL *xmlFile = [NSURL URLWithString:appFile]; 
NSXMLParser *addressParser = [[NSXMLParser alloc] initWithContentsOfURL:xmlFile]; 

: XML을 구문 분석

NSURL *xml = [NSURL URLWithString:@"http://www.example.com/example.xml"]; 
NSString *data = [[NSString alloc] initWithContentsOfURL:xml encoding:NSUTF8StringEncoding error:nil]; 
[data writeToFile:appFile atomically:YES encoding:NSUTF8StringEncoding error:nil]; 

위의 코드는 NULL을 반환하고 오류는 반환하지 않습니다. 나는 똑같은 것을 묘사하는 포럼에 또 다른 게시물을 발견했지만, 나는 그것을 다시 찾을 수 없으며 게시물에는 아무런 대답이 없었다.

누군가 도움을 줄 수 있기를 바랍니다. 기본적으로 파일에 웹 xml을 저장 한 다음 NSXMLParser에 제공하는 것입니다.

답변

6

변경이 줄이에

NSURL *xmlFile = [NSURL URLWithString:appFile]; 

:

NSURL *xmlFile = [NSURL fileURLWithPath:appFile]; 

appFile 로컬 파일 시스템 경로가 아닌 인터넷 URL이기 때문입니다.

관련 문제