[SOLVED] Save QDomDocument to xml

  • Once built a QDomDocument

    QDomDocument doc("MyML");
    QDomElement root = doc.createElement("MyML");

    QDomElement tag = doc.createElement("Greeting");

    QDomText t = doc.createTextNode("Hello World");

    QString xml = doc.toString();

    how can I save it to an xml file?

  • hi
    Writing a DOM document to a file
    QFile file( "simple.xml" );
    if( !file.open( QIODevice::WriteOnly | QIODevice::Text ) )
    qDebug( "Failed to open file for writing." );
    return -1;
    QTextStream stream( &file );
    stream << document.toString();

  • Thanks, it works!
    There's an equivalent of QXmlStreamWriter writeStartDocument() for QDomDocument?

  • hi
    if your problem is solved then make thread title as solved.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.