QDomDocument doc; QDomElement root = doc.createElement("root"); doc.appendChild(root); // Create a CDATA section and set its value QDomCDATASection cdata = doc.createCDATASection("some content"); // Add the CDATA section as a child of the root element root.appendChild(cdata);
QDomDocument doc; QDomElement root = doc.createElement("root"); doc.appendChild(root); // Create a new element and add it as a child of the root element QDomElement elem = doc.createElement("elem"); root.appendChild(elem); // Create a CDATA section and set its value QDomCDATASection cdata = doc.createCDATASection("some content"); // Insert the CDATA section before the element in the document root.insertBefore(cdata, elem);In this example, a new QDomDocument object is created and a root element is added to it. Then, a new element is created and added as a child of the root element. Afterwards, a CDATA section node is created with the createCDATASection() function and its value is set to some XML content. Finally, the CDATA section node is inserted before the element using the insertBefore() function. Package library: Qt Core library.