writetofile xml不工作ipad-air

时间:2014-10-27 15:34:10

标签: objective-c ipad ios7 writetofile

我正在使用Xcode 5,我需要为iPad Air构建一个iOS应用程序。该应用程序需要将数据写入XML文件。一些如何写入xml文件。这是我的代码

NSString *applicationDocumentDir=  [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES) objectAtIndex:0];

NSString *path = [applicationDocumentDir stringByAppendingPathComponent:@"Response.xml"];


NSMutableArray *SurvayData=[[NSMutableArray alloc]init];

SurvayData=[self loadDatafromNsUserDefault];



XMLWriter *objXmlWriter=[[XMLWriter alloc]init];


[objXmlWriter writeStartDocumentWithEncodingAndVersion:@"UTF-8" version:@"1.0"];
[objXmlWriter writeStartElement:@"Response"];
[objXmlWriter writeStartElement:@"Question"];
[objXmlWriter writeAttribute:@"Number" value:@"52"];
[objXmlWriter writeAttribute:@"OptionID" value:@"2"];
[objXmlWriter writeAttribute:@"Comments" value:@"Test "];
[objXmlWriter writeEndElement];
[objXmlWriter writeEndElement];
[objXmlWriter writeEndDocument];

NSString *stringXML=[objXmlWriter toString];






   NSError  *error=nil;
   bool success=[stringXML writeToFile:path atomically:TRUE encoding:NSUTF8StringEncoding error:&error];

但没有成功。你们有什么建议吗?我在这里做错了吗?

0 个答案:

没有答案