[SOLVED] Save QDomDocument to xml



  • Once built a QDomDocument

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

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

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

    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();
    file.close();
    @



  • 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.