#include#include int main() { QDomDocument doc("mydocument"); QDomElement root = doc.createElement("root"); doc.appendChild(root); QString xml; QTextStream stream(&xml); root.save(stream, QDomNode::EncodingFromTextStream); return 0; }
#includeIn this example, we create a QDomDocument and a root element as before. We then create a QFile object and open it in write mode. We create a QTextStream object for the file and call the save function on the root element. Finally, we close the file. Overall, the QDomElement save function is a convenient way to write XML data in C++. It is a part of the Qt library, which provides a variety of other XML-related functionality as well.#include int main() { QDomDocument doc("mydocument"); QDomElement root = doc.createElement("root"); doc.appendChild(root); QFile file("mydocument.xml"); if (file.open(QIODevice::WriteOnly)) { QTextStream stream(&file); root.save(stream, QDomNode::EncodingFromTextStream); file.close(); } return 0; }