I\'m using libxml2 to read/write xml files. Now I\'m trying to write a CDATA node.
Here is what I tried:
nodePtr = xmlNewChild( parentPtr, NULL, \"f
I cannot say for all versions of libxml2, but according to libxml2-2.9.4 the doc
part of returning node of xmlNewChild
comes from its parent. Also the parent of child node returned from xmlNewCDataBlock
is set by doc parameter. So the following would be a good practice:
const char str[] = "said the kitty";
xmlNodePtr node = xmlNewNode(NULL, BAD_CAST "meow");
xmlNodePtr cdata_node = xmlNewCDataBlock(node->doc, BAD_CAST str, strlen(str));
xmlAddChild(node, cdata_node);
The resulting xml is
And it would not matter if node
is part of an xmlDoc
or not