#include#include int main() { // Create a new QDomDocument QDomDocument doc; // Create a root element named "root" QDomElement root = doc.createElement("root"); // Add some child elements to the root element QDomElement child1 = doc.createElement("child1"); QDomElement child2 = doc.createElement("child2"); root.appendChild(child1); root.appendChild(child2); // Print out the XML document as a string QString xml = doc.toString(); qDebug() << xml; return 0; }
#includeIn this example, we create a new QDomDocument and create a root element named "root". We then add two attributes to the root element named "foo" and "baz". Finally, we print out the XML document as a string using the QDomDocument::toString() function. The QDomDocument class is part of the QtCore module in Qt.#include int main() { // Create a new QDomDocument QDomDocument doc; // Create a root element named "root" QDomElement root = doc.createElement("root"); // Add some attributes to the root element root.setAttribute("foo", "bar"); root.setAttribute("baz", 123); // Print out the XML document as a string QString xml = doc.toString(); qDebug() << xml; return 0; }