Writing a CDATA Block to an NSXMLDocument File

How can I write a CDATA block to an XML file and save it to a file in cocoa.

+3
source share
1 answer

To create a node containing encoded CDATA text, use the initWithKind: options: method in NSXMLNode.

NSXMLNode *cdataNode = [[NSXMLNode alloc] initWithKind:NSXMLTextKind  options:NSXMLNodeIsCDATA];
[cdataNode setStringValue:@"<some text>"];

And to write the XML data to a file :

NSData *xmlData = [xmlDoc XMLDataWithOptions:NSXMLNodePrettyPrint];
[xmlData writeToFile:fileName atomically:YES];
+5
source

Source: https://habr.com/ru/post/1735872/