3

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

boom
  • 5,856
  • 24
  • 61
  • 96

1 Answers1

5

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

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

And to write xml data to a file:

NSData *xmlData = [xmlDoc XMLDataWithOptions:NSXMLNodePrettyPrint];
[xmlData writeToFile:fileName atomically:YES];
Lachlan Roche
  • 25,678
  • 5
  • 79
  • 77