iOS中创建XML

NSMutableString *xmlString = [NSMutableString stringWithString:@"<?xml version='1.0' encoding='UTF-8'?>"];
[xmlString appendString:@"<chats>"];
for(NSDictionary *chatInfo in chatArray) {
	[xmlString appendFormat:@"<chat><speaker><![CDATA[%@]]></speaker><text><![CDATA[%@]]></text></chat>", [chatInfo objectForKey:@"speaker"],
	 [chatInfo objectForKey:@"text"]];
}
[xmlString appendString:@"</chats>"];
	
NSError *error;
[xmlString writeToFile:chatFile atomically:YES encoding:NSUTF8StringEncoding error:&error];

  

没什么特别的,其实就是将xml格式的字符串写到文件里而已。

你可能感兴趣的:(ios,xml,iPhone)