#include#include int main() { QDomDocument doc; QDomElement root = doc.createElement("root"); doc.appendChild(root); QDomElement child1 = doc.createElement("child1"); QDomElement child2 = doc.createElement("child2"); root.appendChild(child1); root.insertBefore(child2, child1); return 0; }
#includeIn this example, we create the same QDomDocument and root element as before, but this time we add child2 to the root element's node list before any other child element (using nullptr as the second parameter). We then use insertBefore() again to add child1 before child2. The resulting node list will be: child1, child2. The xmlDoc module from the Qt library provides the QDomElement class and its associated functions, including insertBefore().#include int main() { QDomDocument doc; QDomElement root = doc.createElement("root"); doc.appendChild(root); QDomElement child1 = doc.createElement("child1"); QDomElement child2 = doc.createElement("child2"); root.insertBefore(child2, nullptr); root.insertBefore(child1, child2); return 0; }