#includeint main() { QDomDocument xmlDocument; xmlDocument.setContent(" "); QDomElement rootElement = xmlDocument.documentElement(); QDomElement childElement = rootElement.firstChildElement(); QDomNode parentNode = childElement.parentNode(); QDomDocument parentDocument = parentNode.ownerDocument(); return 0; }
#includeIn this example, a new QDomDocument object is created and a processing instruction is added to it using the createProcessingInstruction() function. The first child element of the root element is obtained and passed to the appendChild() function of the processing instruction node, making it the new parent of the child element. Finally, the replaceChild() function is used to replace the child element with the processing instruction node as the child of the root element. Package library: QtGuiint main() { QDomDocument xmlDocument; xmlDocument.setContent(" "); QDomElement rootElement = xmlDocument.documentElement(); QDomElement childElement = rootElement.firstChildElement(); QDomDocument newDocument; QDomNode newParentNode = newDocument.createProcessingInstruction("xml", "version=\"1.0\" encoding=\"utf-8\""); newParentNode.appendChild(childElement); rootElement.replaceChild(newParentNode, childElement); return 0; }