2012-11-08 53 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 –