将CDATA块写入NSXMLDocument文件

boo*_*oom 3 cocoa nsxml

如何在XML文件中写入CDATA块并将其保存到cocoa中的文件中.

Lac*_*che 5

要创建包含CDATA编码文本的节点,请在NSXMLNode上使用方法initWithKind:options : .

NSXMLNode *cdataNode = [[NSXMLNode alloc] initWithKind:NSXMLTextKind  options:NSXMLNodeIsCDATA];
[cdataNode setStringValue:@"<some text>"];
Run Code Online (Sandbox Code Playgroud)

并将xml数据写入文件:

NSData *xmlData = [xmlDoc XMLDataWithOptions:NSXMLNodePrettyPrint];
[xmlData writeToFile:fileName atomically:YES];
Run Code Online (Sandbox Code Playgroud)