2012-11-08 51 views

回答

0

首先創建xml值並將其存儲爲字符串。 然後使用以下方法在文檔目錄中創建xml文件。

//方法將一個字符串寫入到一個XML文件

-(void) writeToXMLFile:(NSString *)content 
{ 

    //get the documents directory: 
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    NSString *documentsDirectory = [paths objectAtIndex:0]; 

    //make a file name to write the data to using the documents directory: 
    NSString *fileName = [NSString stringWithFormat:@"%@/xmlfile.xml",documentsDirectory]; 

    //save content to the documents directory 
    [content writeToFile:fileName atomically:NO encoding:NSStringEncodingConversionAllowLossy error:nil]; 

} 
+0

我不知道我怎麼能「首先創建和XML值存儲爲一個字符串」實現這個part.I'm新XML 。 –

+0

@subham:請查看http://www.raywenderlich.com/725/how-to-read-and-write-xml-documents-with-gdataxml瞭解更多 –

+0

@subham:NSString * str = @「<? xml version =「1.0」encoding =「UTF-8」?> Midhun「;簡單的XML使用nsstring –