Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to put the content of these 4 XML files into one XML file?



  • I have Created the four windows (Four Forms) and i linked together by using signal slot..For example, if i click next button in the 1st window the 2nd window opens ,like wise i do for all remaining as well as i have store the combobox text in xml by clicking next button ,So i created 4 xml and now if i press the ok button in the first page i want to link all xml and i want to show in all in one XML ,I tried a lot but i cant't please try and help me to resolve it Guys ..

    firstpage code

           QString filename1 = QDesktopServices::storageLocation(QDesktopServices::DataLocation)+"/home/newuser/Desktop/filenamemw.xml";
       QFile file("/home/newuser/Desktop/filenamemw.xml");
       if(!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
       qDebug() << "Open the file for writing failed";
      } else {
        QTextStream stream(&file);
        stream << document.toString();
        file.close();
        qDebug() << "Writing is done";
    

    second page code,
    QFile file("/home/newuser/Desktop/setting1xmlpage2.xml");
    if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
    return;

    third page code,

      QFile file("/home/newuser/Desktop/setting2xmlpage3.xml");
    if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
        return;
    
    
    
    QXmlStreamWriter stream(&file);
    stream.setAutoFormatting(true);
    stream.writeStartDocument();
    

    fourth page ,

            QFile file("/home/newuser/Desktop/setting3xmlpage4.xml");
    if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
        return;
    
    
    
    QXmlStreamWriter stream(&file);
    stream.setAutoFormatting(true);
    stream.writeStartDocument();
    

    Thanks in advance


  • Qt Champions 2019

    @sankarapandiyan I don't understand your description: do you want to put the content of these 4 XML files into one XML file?
    Why not simply write all the content into one XML file from the beginning instead of writing into 4 files and then merging them?



  • @jsulm yes ,you are saying right but i am not aware of this at my starting point ...

    : do you want to put the content of these 4 XML files into one XML file?

    yes you are ryt!.please try to resolve it please



  • @sankarapandiyan
    Given that they are currently separate, I'm not sure what you want to do from here? Do you want to merge them into a single file and from then do it that way from now onwards?

    I do everything I can with XML documents rather than streams, it's just easier. To merge this way you will need to:

    1. Read each of your files into its own http://doc.qt.io/qt-5/qdomdocument.html

    2. Use http://doc.qt.io/qt-5/qdomdocument.html#importNode to import into one of them each of the others. You should be able to just import the other documents' http://doc.qt.io/qt-5/qdomdocument.html#documentElement, IIRC, so just one node.

    3. Save the QDomDocument you've imported the others into.



  • @JonB said in How to put the content of these 4 XML files into one XML file?:

    I'm not sure what you want to do from here?

    @JonB said in How to put the content of these 4 XML files into one XML file?:

    Do you want to merge them into a single file

    yes i want to merge ...

    @JonB sure i will try


Log in to reply