#includeint main() { QDomDocument doc("mydocument"); QDomElement root = doc.createElement("root"); doc.appendChild(root); QDomElement child1 = doc.createElement("child1"); root.appendChild(child1); return 0; }
void appendElement(QDomDocument& doc, QDomElement& parent, QString tagName, QString value) { QDomElement element = doc.createElement(tagName); QDomText text = doc.createTextNode(value); element.appendChild(text); parent.appendChild(element); } int main() { QDomDocument doc("mydocument"); QDomElement root = doc.createElement("root"); doc.appendChild(root); appendElement(doc, root, "child1", "value1"); appendElement(doc, root, "child2", "value2"); return 0; }This code defines a function that can be used to append new elements to an existing XML document. It creates a new element, adds a text node with a value to it, and then appends it to a parent element using the appendChild function. The main function creates an XML document with a root element and then adds two child elements to it using the appendElement function. These examples use the QtXml module to work with XML files in Qt.